Skip to content

Fix repeated PDF exports accumulating object references - #352

Open
ac1982 wants to merge 1 commit into
signintech:masterfrom
ac1982:fix/repeated-pdf-exports
Open

ac1982 wants to merge 1 commit into
signintech:masterfrom
ac1982:fix/repeated-pdf-exports

Conversation

@ac1982

@ac1982 ac1982 commented Oct 20, 2026

Copy link
Copy Markdown

Repeatedly serializing the same GoPdf appends page and content references again, so a one-page document becomes a two-page PDF on its second export. Protected documents also gain a new encryption object each time.

Rebuild the derived page references during prepare and reuse the existing encryption object. This keeps repeated exports stable while still including pages added after an earlier export.

Fixes #327.

Validation:

  • Regression covers plain/protected documents, embedded text, GetBytesPdfReturnErr, WriteTo, WritePdf, retry after a failed destination write, and adding a page between exports. It fails on the original implementation.
  • mkdir -p test/out && go test -race -count=1 ./... and go vet ./... pass on Go 1.27.1/Linux arm64.
  • External pdfinfo check: export, repeat export, then add a page produces page counts 1/1/2, versus 1/2/4 and syntax errors before the fix.

The existing behavior where WriteTo discards writer errors is unchanged; the retry test checks document stability, not error propagation.

@oneplus1000

Copy link
Copy Markdown
Collaborator

Thanks @ac1982 for your PR! I normally check PRs on weekends. However, I have to go out of town this weekend, so I might reply a bit later than usual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subsequent WritePdf, GetBytesPdf, ... causes the PDF to be broken and multiplied

2 participants