Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PdfDocumentBuilder creates broken annotation highlights when copying pages from source PDFs #1000

Open
cremor opened this issue Feb 27, 2025 · 0 comments
Labels
document-editing Related to creating or editing/modifying documents

Comments

@cremor
Copy link

cremor commented Feb 27, 2025

I'm using PdfDocumentBuilder.AddPage to merge multiple PDF files. When the source PDF contains annotations that highlight regions then the created (merged) PDF has some problems with those annotations. The problems differ based on the PDF reader application:
With Acrobat Reader: The annotations change their color and can't be removed any more.
With Firefox: The annotations don't show a tooltip any more.

But this problem only happens if at least a page is inserted before the copied page. So maybe there is a problem with page numbers/references in the created file?

If you don't have any time to look at this right now, could you then please point me to the right place where I could start looking to fix this myself?

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);

// This line is important to reproduce the problem!
outputDocument.AddPage(PageSize.A4);

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

I've tested the following versions of PdfPig, all are affected:

  • 0.1.8
  • 0.1.9
  • 0.1.10-alpha-20250224-f26e7

Expected output:
The annotations should show tooltips in Firefox.
It should be possible to delete the annotations in Acrobat Reader (via the delete icon that appears after clicking on the annotation Image)
The annotation colors should look like this:
Image

Actual output:
The annotations don't show a tooltip in Firefox.
The annotations can't be deleted in Acrobat Reader.
The annotation colors change shortly after scrolling and look like this in Acrobat Reader:
Image

@BobLd BobLd added the document-editing Related to creating or editing/modifying documents label Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
document-editing Related to creating or editing/modifying documents
Projects
None yet
Development

No branches or pull requests

2 participants