Skip to content

PdfDocumentBuilder creates broken annotation elements when copying pages from specific source PDFs #878

@cremor

Description

@cremor

I have an application that uses PdfPig to merge multiple PDF files. I'm using PdfDocumentBuilder.AddPage for this.
The users of the application have reported a few cases where the created (merged) PDF has missing elements (mostly annotations).

Depending on the PDF viewer application the elements are either:

  • Completely missing (e.g. in Acrobat Reader)
  • Visible, but rotated (e.g. in Wondershare PDFelement, Google Chrome and Microsoft Edge)
  • Correctly shown (e.g. in Mozilla Firefox)

Sample input file: Input.pdf

Sample code:

string inputFile = @"C:\Data\Input.pdf";
string outputFile = @"C:\Data\Output.pdf";

using var targetStream = File.Open(outputFile, FileMode.Create, FileAccess.Write);
using var outputDocument = new PdfDocumentBuilder(targetStream);
using var inputDocument = PdfDocument.Open(inputFile);

for (int i = 1; i <= inputDocument.NumberOfPages; i++)
{
    outputDocument.AddPage(inputDocument, i);
}

I've tested multiple versions of PdfPig and here are the results:

  • 0.1.8: Created PDF looks correct
  • 0.1.9-alpha-20240219-c2536: Created PDF is broken
  • 0.1.9-alpha-20240312-845e3: Created PDF is broken
  • 0.1.9-alpha-20240721-a99c0 (current version): Created PDF is broken

Input:
grafik

Output when shown in Acrobat Reader:
grafik

Ouput when shown in Microsoft Edge:
grafik

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdocument-editingRelated to creating or editing/modifying documents

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions