public ActionResult <DocumentId> UploadDocument(DocumentUpload documentUpload) { int length = 0; if (String.IsNullOrEmpty(documentUpload.Text)) { documentUpload.Text = PDFService.GetTextFromPDFBytes(documentUpload.Contents); length = documentUpload.Contents.Length; } else { length = documentUpload.Text.Length; } string id = DocumentService.SaveDocumentDataFromText(documentUpload.Email, length, documentUpload.Text); if (string.IsNullOrWhiteSpace(id)) { return(NotFound()); } else { return(Ok(new DocumentId { Id = id })); } }
public HttpResponseMessage getPDF(string RegistroClinicoId) { var response = new HttpResponseMessage(HttpStatusCode.OK); try { var service = new PDFService(); var registro = service.PDFRegistroHistoria(RegistroClinicoId); var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter(); var pdfBytes = htmlToPdf.GeneratePdf(registro); var stream = new MemoryStream(pdfBytes); response.Content = new StreamContent(stream); response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf"); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "RegistroClinico.pdf" }; } catch (Exception ex) { // response.State = false; // response.Message = ex.Message; } return(response); }
public IndexModel(ApplicationDbContext ctx, IOptions <Discounts> discounts, EmailSender emailSender, PDFService pdfService, ILogger <IndexModel> logger, IDeviceResolver deviceResolver) { _ctx = ctx; _discounts = discounts; _emailSender = emailSender; _pdfService = pdfService; this.logger = logger; device = deviceResolver.Device; }
public PDFController(IConfiguration config, PDFService pDFService, IViewRenderService viewRenderService, ApplicationDbContext context, IOptions <Discounts> discounts, EmailSender emailSender) { _config = config; _pdfService = pDFService; _viewRenderService = viewRenderService; _context = context; _discounts = discounts; _emailSender = emailSender; }
private void btnPdf_Click(object sender, EventArgs e) { if (LekarskoUverenje != null || Pregled != null || ValidateInputs()) { PDFService.GeneratePDFDocument(Pregled ?? LekarskoUverenje.Pregled, (cmbZdravstvenoStanje.SelectedItem as ZdravstvenoStanjeDto)?.Opis ?? string.Empty, txtOpisStanja.Text); } }
// POST: PDF/PDFModel/Edit/5 // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. public ActionResult Generate(int id) { MemoryStream stream = new MemoryStream(); PDFModel pdfModel = db.PDFs.Find(id); PDFService pdfService = new PDFService(); PDFFileModel pdfFile = pdfService.HtmlToPdf("filename", pdfModel.HtmlContent, UserId, options: new string[] { "--disable-external-links", "--disable-internal-links" }); return(File(pdfFile.FilePathAndName, "application/pdf", pdfFile.FileName)); }
public void DaoTest() { var service = new PDFService(new StorageStatusDao()); using (var fs = new FileStream(@"/opt/pdf-server/assets/README.pdf", FileMode.Open, FileAccess.Read)) { var bytes = new byte[fs.Length]; fs.Read(bytes, 0, (int)fs.Length); Assert.Equal(bytes, service.GetPDFData("115000", 1)); } }
public ActionResult GeneratePDFOutput() { // Get BookID, VersionID & Year from Cookie var pContext = System.Web.HttpContext.Current; var lCookieData = CookieManagement.GetCookie(pContext); var lLogMsg = string.Empty; var pdfService = new PDFService(); try { // Print Output for given BookID var pdfModel = new PDFDocumentModel { Book = lCookieData.Book, BookID = Convert.ToInt32(lCookieData.BookID), Publisher = lCookieData.Publisher, PublisherID = Convert.ToInt32(lCookieData.PublisherID), VersionID = lCookieData.VersionID, Year = lCookieData.Year }; var lResult = pdfService.BuildPDF(pdfModel, pContext); if (lResult.Any()) { // Set Up the Response Stream for the Spec Sheet Collection System.Web.HttpContext.Current.Response.Clear(); System.Web.HttpContext.Current.Response.BufferOutput = false; System.Web.HttpContext.Current.Response.ContentType = "application/pdf"; System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + "loreal_output.pdf"); // Create a FileStream for the PDF and Send it to the Response's OutputStream using (var outStream = new FileStream(pdfService.FilePath, FileMode.Open)) { byte[] buffer = new byte[4096]; int count = 0; while ((count = outStream.Read(buffer, 0, buffer.Length)) > 0) { System.Web.HttpContext.Current.Response.OutputStream.Write(buffer, 0, count); System.Web.HttpContext.Current.Response.Flush(); } } } } catch (Exception ex) { var lReturnMessage = String.Format("Error in PrintPDFOutput. BOOK: {0}, Publisher: {1}.", lCookieData.Book, lCookieData.Publisher); lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}. SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace); logger.Error(lLogMsg); } return(View()); }
//public HttpResponseMessage PrintPDFOutput() //public System.Web.Mvc.ActionResult PrintPDFOutput() public IHttpActionResult PrintPDFOutput() { // Get BookID, VersionID & Year from Cookie var pContext = System.Web.HttpContext.Current; var lCookieData = CookieManagement.GetCookie(pContext); var lLogMsg = string.Empty; var pdfService = new PDFService(); try { // Print Output for given BookID var pdfModel = new PDFDocumentModel { Book = lCookieData.Book, BookID = Convert.ToInt32(lCookieData.BookID), Publisher = lCookieData.Publisher, PublisherID = Convert.ToInt32(lCookieData.PublisherID), VersionID = lCookieData.VersionID, Year = lCookieData.Year }; var lResult = pdfService.BuildPDF(pdfModel, pContext); if (lResult.Any()) { // Set up the Response Stream for the File HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.Expires = -1000; //HttpContext.Current.Response.BufferOutput = false; HttpContext.Current.Response.ContentType = "application/pdf"; HttpContext.Current.Response.AddHeader("content-length", lResult.Length.ToString()); HttpContext.Current.Response.AddHeader("content-disposition", "inline; filename=" + "loreal_output.pdf"); HttpContext.Current.Response.BinaryWrite(lResult); HttpContext.Current.Response.End(); } //} } catch (Exception ex) { var lReturnMessage = String.Format("Error in PrintPDFOutput. BOOK: {0}, Publisher: {1}.", lCookieData.Book, lCookieData.Publisher); lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}. SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace); logger.Error(lLogMsg); } return(Ok(HttpContext.Current.Response)); }
public void FileNotFound() { // IStorageStatusを作成 var testDao = new TestDao(); var status = new StorageStatus(); // 存在しないパスを指定 status.picturePath1 = @"D:\test\test.pdf"; testDao.SetStorageStatus(status); var service = new PDFService(testDao); var ex = Assert.Throws <FileNotFoundException>(() => { service.GetPDFData("", 1); }); }
public ActionResult Get(string id, [FromQuery] int serial) { try { using (var dao = new StorageStatusDao()) { var service = new PDFService(dao); var bytes = service.GetPDFData(id, serial); return(this.File(bytes, "application/octet-stream")); } } catch (Exception) { return(NotFound()); } }
static void Main(string[] args) { LoggerService.WriteLog("Initailizing POC..."); var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json"); IConfiguration config = builder.Build(); Form pdfTemplate = PDFService.LoadPDFDoc(); LoggerService.WriteLog("Listing all PDF template form fields.."); PDFService.ReadPDFForm(pdfTemplate); LoggerService.WriteLog("Setting initial value for PDF and creating output file.."); PDFService.WritePDFForm(pdfTemplate, config); }
public void Pass() { // IStorageStatusを作成 var testDao = new TestDao(); var status = new StorageStatus(); // 存在しないパスを指定 status.picturePath1 = @"D:\test\test.pdf"; // 存在するパスを指定 var filePath = @"/opt/pdf-server/.gitignore"; status.picturePath2 = @"/opt/pdf-server/.gitignore"; testDao.SetStorageStatus(status); var service = new PDFService(testDao); // 成功するはず using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { var bytes = new byte[fs.Length]; fs.Read(bytes, 0, (int)fs.Length); Assert.Equal(bytes, service.GetPDFData("", 2)); } }
public void Get(string para1, string para2) { string fname = para1 + "_" + para2; string mergedPdfSavePath = mergedfilepath + fname + ".pdf"; PDFService ps = new PDFService(); if (ps.GenerateCombinedPdfForTravelAllowance(LoadApplicationFilesList(para1, Convert.ToInt32(para2)), mergedPdfSavePath) != -1) { string path = mergedPdfSavePath; DownloadFile(path, System.IO.Path.GetFileName(path)); } }
public PDFController(PDFService pDFService) { _PDFService = pDFService; }