Skip to content

Error splitting PDF with PDFSharp 7 vs 6.2.4 #363

@GlSimon

Description

@GlSimon

I am using PDFSharp to split a PDF file into multiple single pages. I am aware 7 is still in preview, so it is nothing i need support on, just to inform you guys

for (int idx = 1; idx <= numberOfPages; idx++) { // create single-page PDF PdfDocument outputDocument = new PdfDocument(); outputDocument.AddPage(inputPDF.Pages[idx-1]); ...save page

Expected Behavior

Every Single page will get added to a document and can then be exported successfully, as it happens with 6.2.4

Actual Behavior

Adding the first page succeeds, but as of the 2nd page an error is thrown.

The given key '12 0' was not present in the dictionary. Order: Stack Trace: at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at PdfSharp.Pdf.Advanced.PdfImportedObjectTable.get_Item(PdfObjectID externalID) at PdfSharp.Pdf.PdfObject.FixUpObject(PdfImportedObjectTable iot, PdfDocument owner, PdfObject value) at PdfSharp.Pdf.PdfObject.ImportClosure(PdfImportedObjectTable importedObjectTable, PdfDocument owner, PdfObject externalObject) at PdfSharp.Pdf.PdfPages.CloneElement(PdfPage page, PdfPage importPage, String key, Boolean deepCopy) at PdfSharp.Pdf.PdfPages.ImportExternalPage(PdfPage importPage) at PdfSharp.Pdf.PdfPages.Insert(Int32 index, PdfPage page) at PdfSharp.Pdf.PdfPages.Add(PdfPage page) at PdfSharp.Pdf.PdfDocument.AddPage(PdfPage page)

Steps to Reproduce the Behavior

Unfortunately i can not provide the PDFs that are causing this issue, but they follow a clear pattern.
The multi page PDFs that are failing always come with a second PDF that is always split successfull. They are digitally created PDFs, very similar in content and layout, but the ones that fail have a graphic/stamp added to every page that is not present on the PDFs that are split successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions