BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
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); }