Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
144118 | Apr 19,2019 09:37 AM UTC | Apr 29,2019 12:28 PM UTC | ASP.NET MVC - EJ 2 | 5 |
![]() |
Tags: PDF |
private FileResult JoinPdfwithAnnotations(string imageData, MemoryStream stream, string contentType, string fileName) { byte[] pdfBytes; //Returns the pdf document without annotations if (string.IsNullOrEmpty(imageData)) { pdfBytes = stream.ToArray(); return File(pdfBytes, contentType, fileName); } List<string> base64AnnotationsList = imageData.Split(',').ToList(); PdfLoadedDocument pdfDocument = new PdfLoadedDocument(stream); try { foreach (string base64Annotation in base64AnnotationsList) { PdfImage image; byte[] data = Convert.FromBase64String(base64Annotation); using (MemoryStream imageStream = new MemoryStream(data, 0, data.Length)) { image = PdfImage.FromStream(imageStream); } PdfLoadedPage pdfPage = (PdfLoadedPage) pdfDocument.Pages[base64AnnotationsList.IndexOf(base64Annotation)]; if (pdfPage != null) { PdfGraphics gfx = pdfPage.Graphics; gfx.DrawImage(image, 0, 0); } else { LogManager.Instance.Error($"The image cannot be draw on pdf {fileName}"); } pdfDocument.Save(); } pdfBytes = stream.ToArray(); } finally { pdfDocument.Close(true); stream.Close(); } return File(pdfBytes, contentType, fileName); }
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.