Hi all,
I try to put an image from stream on some PDF and the picture does't appears. The problem is that no error is thrown and I cannot figure out the problem.
I put in attachments one PDF that does't work good. I also tried to put in this an image from path(using PdfImage.FromFile) or to draw on document some figures(like DrawString, DrawRectangle, DrawLine and doesn't work at all.
I have one more file that has the same behavior(the orientation is portrait), but i don't have rights to put here. Thanks.
There is the code:
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);
}
Attachment:
PDF_949ce2eb.zip