Bear with me, this is hard to explain.....
I am using MigraDoc to create a PDF, very successfully. I have now identified a requirement to take the pages from a second, existing PDF and effectively embed each page as an image into the PDF that I am creating. I have got this far:
Code:
private void AddPdf(Cell cell, byte[] pdf)
{
var stream = new MemoryStream(pdf);
var document = PdfReader.Open(stream);
var pageCount = 0;
foreach (var pdfPage in document.Pages)
{
pageCount++;
cell.AddParagraph("Page " + pageCount);
// Need to add the PDF page itself here
}
}
I have a PDF in the byte array, and I think it is being understood because the number of pages found is correct.
I have read
here that it is possible to create an image from a PDF page. However, I am struggling to get anywhere with the PdfPage object that I have. I suspect I am muddled because the example is based on MigraDoc, but I have a PDFsharp object.
I did discover that if I do this, with my PDF byte array in content:
Code:
var image = "base64:" + Convert.ToBase64String(content);
cell.AddImage(image);
Then I do appear to get the first page of the PDF embedded as an image in the document that I am creating. That is very close to what I need, but I need to get each page in turn, not just the first.
I feel like I am very close and just need a push in the right direction.
Thanks,
Nick