Repository navigation
Conversation
The JavaDoc of PdfStamper(PdfReader, OutputStream, String, boolean) claimed that appending the changes as a new revision gains nothing in speed or memory. That is not how it works: in append mode the original bytes are copied unchanged and only the new and modified objects are written, while the default constructors re-read and re-serialize every object of the document. On a 45-page document with about 23,000 objects, stamping a small text on every page measured roughly 250 ms without append and 140 ms with append = true (issue LibrePDF#1598). The JavaDoc now describes the incremental revision, the speed and memory gain, and the restrictions of append mode (error-free document required, encryption status cannot be changed, flattening not supported). A test verifies that append mode keeps the original bytes as a prefix of the output and that the default mode rewrites the document.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 6 |
| Duplication | 3 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description of the new Feature/Bugfix
Issue #1598 reports that
PdfStamperwithappend = trueis dramatically faster than the default constructor, while its JavaDoc claims the opposite ("nothing is gained in speed or memory").The JavaDoc is outdated, and this PR corrects it. What
appendreally does, measured on master with a generated 45-page document holding about 23,000 objects (Java 25, best of three runs):append = trueThe gain grows with document size and object count. The reason is structural: in append mode the original bytes are copied unchanged to the output and only the new and modified objects are written as an incremental revision, while the default constructors re-read and re-serialize every object of the document.
The JavaDoc of
PdfStamper(PdfReader, OutputStream, String, boolean)and the bare@param appendofPdfStamperImpnow describe:Fixes #1598
Unit-Tests for the new Feature/Bugfix
PdfStamperAppendModeTestverifies that append mode keeps the original bytes unchanged as a prefix of the output and produces a readable document containing the added content, and that the default mode rewrites the whole document (not an incremental revision). No timing assertions, so the tests stay stable in CI.Compatibilities Issues
None. Documentation-only change plus a new test; no method signatures or behaviour are changed. The changelog entry is in
changelogs/4.0.1.md. The same JavaDoc text exists on the3.0-java21branch and can be ported there if wanted.Your real name
Vadim Lazuk
Testing details
./mvnw -pl openpdf-core test: 2595 tests, 0 failures, 0 errors, 3 skipped../mvnw -pl openpdf-core checkstyle:check: passes.