-
Notifications
You must be signed in to change notification settings - Fork 282
Closed
Description
First, thanks for maintaining PdfPig. It's a great boon we've been using for ages. Recently, we started converting various text formats into PDFs via Pandoc with WeasyPrint as --print-engine
. We consistently hit the following issue when copying pages from such a PDF (against 0754e7f):
UglyToad.PdfPig.Core.PdfDocumentFormatException: Expected a IndirectReferenceToken for the XObject, got a DictionaryToken
at UglyToad.PdfPig.Writer.PdfPageBuilder.CopyFrom(Page srcPage)
Our code:
using PdfDocument document = PdfDocument.Open(fullPath);
await using FileStream outputStream = new FileStream(distPath, FileMode.Create, FileAccess.Write);
using PdfDocumentBuilder pdfWriter = new PdfDocumentBuilder();
for (int i = pageFrom; i <= pageTo; i++)
{
Page page = document.GetPage(i);
PdfPageBuilder newPage = pdfWriter.AddPage(page.Width, page.Height);
newPage.CopyFrom(page);
}
byte[] newPdf = pdfWriter.Build();
await outputStream.WriteAsync(newPdf);
Sample PDF:
sample.pdf
Metadata
Metadata
Assignees
Labels
No labels