public ActionResult GenerateMultiPdf(string a, string l, string resync) { var sep = new[] { '|' }; var ios = a.Split(sep, StringSplitOptions.RemoveEmptyEntries); var lineNos = l.Split(sep, StringSplitOptions.RemoveEmptyEntries); if (ios.Any() && lineNos.Any() && ios.Count().Equals(lineNos.Count())) { var allDocs = new Doc(); byte[] pdfs = null; for (var i = 0; i < ios.Count(); i++) { CreateAndAppendDeliveryAssurancesPdf(Request, ios[i], Convert.ToInt32(lineNos[i]), resync == "1", ref allDocs, ref pdfs); } allDocs.ClearCachedDecompressedStreams(); allDocs.Clear(); allDocs.Dispose(); if (pdfs != null) { Response.AddHeader("Content-Disposition", "inline; filename=DeliveryAssurances.pdf"); return(File(pdfs, "application/pdf")); } } return(HttpNotFound()); }
private byte[] CreateDeliveryAssurancePdf(HttpRequestBase request, string id, int lineNumber, bool resync, ref Doc theDoc) { int retID = 0; theDoc = new Doc(); if (resync) { theDoc.HtmlOptions.Engine = EngineType.Gecko; theDoc.HtmlOptions.PageCacheEnabled = false; theDoc.HtmlOptions.UseNoCache = true; theDoc.HtmlOptions.PageCacheClear(); theDoc.HtmlOptions.PageCachePurge(); theDoc.HtmlOptions.UseResync = true; } theDoc.Rect.Inset(20, 20); theDoc.ClearCachedDecompressedStreams(); var generatePdfUrl = DeliveryAssuranceHelper.BuildQueryUrl($"{GenerateDeliveryPdfUrl}GeneratePdf", new Dictionary <string, string>() { { "a", id }, { "l", lineNumber.ToString() } }); var responseStream = GetWebResponseStream(request, generatePdfUrl); if (responseStream != null) { var outerHtml = FixRelativeLinksToAbsolute(responseStream, request.Url); Log.DebugFormat("HtmlResponse with relative links {0}", outerHtml); retID = theDoc.AddImageHtml(outerHtml); } else { Log.DebugFormat("PDFResponseStream was null"); } //Add Barcode theDoc.Rect.String = "360 680 590 725"; //theDoc.Rect.String = "360 695 590 740"; var bdf = BarcodeDrawFactory.Code39WithoutChecksum; var image = bdf.Draw(id, 45); theDoc.AddImageBitmap(new Bitmap(image), true); theDoc.Rect.String = "460 650 530 670"; theDoc.AddText(id); //Add Footer theDoc = AddFooter(theDoc, id, lineNumber); var theData = theDoc.GetData(); return(theData); }
public bool ConvertToImage(string pdfPath, string toSaveImagePath, ILogger logger, bool hideSection, List <RectangleDimesion> rectangles, List <RectangleDimesion> highQualityRectangles = null) { if (pdfPath.IndexOfAny(Path.GetInvalidPathChars()) != -1) { return(false); } if (toSaveImagePath.IndexOfAny(Path.GetInvalidPathChars()) != -1) { return(false); } if (File.Exists(pdfPath)) { var doc = new Doc(); string tempSavePath = hideSection ? Directory.GetParent(toSaveImagePath).FullName + "\\temp.jpg" : toSaveImagePath; try { doc.Read(pdfPath); doc.PageNumber = 1; doc.Rendering.Save(tempSavePath); } catch (Exception ex) { logger.Error("System Failure! File could not be generated. Message: " + ex.Message + " \n\t " + ex.StackTrace); return(false); } finally { doc.ClearCachedDecompressedStreams(); doc.Clear(); doc.Dispose(); } if (hideSection) { HideEcgFinding(tempSavePath, toSaveImagePath, logger, rectangles); } var imageName = _settings.HighImageQuality + Path.GetFileName(toSaveImagePath); var directoryToSave = Directory.GetParent(toSaveImagePath).FullName; var highQualityImage = Path.Combine(directoryToSave, imageName); ConvertToHighQualityImage(pdfPath, highQualityImage, logger, hideSection, highQualityRectangles); return(true); } return(false); }
public ActionResult GenerateDryingAgrementPdf(string resync = "true") { var theDoc = new Doc(); var pdf = CreateDryingAgreementPdf(Request, resync == "true", ref theDoc); theDoc.ClearCachedDecompressedStreams(); theDoc.Clear(); theDoc.Dispose(); if (pdf == null) { return(HttpNotFound()); } Response.AddHeader("Content-Disposition", "inline; filename=DryingAgreement.pdf"); return(File(pdf, "application/pdf")); }
private void CreateAndAppendDeliveryAssurancesPdf(HttpRequestBase request, string id, int lineNumber, bool resync, ref Doc allDocs, ref byte[] pdfOut) { var theDoc = new Doc(); CreateDeliveryAssurancePdf(request, id, lineNumber, resync, ref theDoc); if (allDocs == null) { allDocs = new Doc(); } allDocs.Append(theDoc); pdfOut = allDocs.GetData(); theDoc.ClearCachedDecompressedStreams(); theDoc.Clear(); theDoc.Dispose(); }
private byte[] CreateDryingAgreementPdf(HttpRequestBase request, bool resync, ref Doc theDoc) { var retID = 0; theDoc = new Doc(); if (resync) { theDoc.HtmlOptions.Engine = EngineType.Gecko; theDoc.HtmlOptions.PageCacheEnabled = false; theDoc.HtmlOptions.UseNoCache = true; theDoc.HtmlOptions.PageCacheClear(); theDoc.HtmlOptions.PageCachePurge(); theDoc.HtmlOptions.UseResync = true; } theDoc.Rect.Inset(20, 20); theDoc.ClearCachedDecompressedStreams(); const string generatePdfUrl = "/api/drying-agreement/generatePdf"; var responseStream = GetWebResponseStream(request, generatePdfUrl); if (responseStream != null) { var outerHtml = FixRelativeLinksToAbsolute(responseStream, request.Url); Log.DebugFormat("HtmlResponse with relative links {0}", outerHtml); retID = theDoc.AddImageHtml(outerHtml); } else { Log.DebugFormat("PDFResponseStream was null"); } var theData = theDoc.GetData(); return(theData); }
public ActionResult GeneratePdf(string a, string l, string resync) { var ioNumber = a; int lineNumber; if (!string.IsNullOrWhiteSpace(ioNumber) && !string.IsNullOrWhiteSpace(l) && int.TryParse(l, out lineNumber)) { var theDoc = new Doc(); var pdf = CreateDeliveryAssurancePdf(Request, ioNumber, lineNumber, resync == "true", ref theDoc); theDoc.ClearCachedDecompressedStreams(); theDoc.Clear(); theDoc.Dispose(); if (pdf != null) { Response.AddHeader("Content-Disposition", "inline; filename=DeliveryAssurance.pdf"); return(File(pdf, "application/pdf")); } } return(HttpNotFound()); }