-
Notifications
You must be signed in to change notification settings - Fork 1.5k
BUG: Fixed merge page bug issue with _markup_annotations objects #3577
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
Open
HSY-999
wants to merge
7
commits into
py-pdf:main
Choose a base branch
from
HSY-999:fixMergePageBugNewFix#3467
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7fd053f
BUG: Fixed merge page bug issue with _markup_annotations objects
HSY-999 2873dda
Merge branch 'main' into fixMergePageBugNewFix#3467
HSY-999 f28b008
Merge branch 'main' into fixMergePageBugNewFix#3467
HSY-999 9fa15e8
rewrite __new__ function call __init__
HSY-999 ccfeb90
Merge branch 'fixMergePageBugNewFix#3467' of github.com:HSY-999/pypdf…
HSY-999 87393a7
revert logic closer to original after discovering double init
HSY-999 1fe2e98
Merge branch 'main' into fixMergePageBugNewFix#3467
HSY-999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -293,7 +293,9 @@ def clone( | |
| visited: set[tuple[int, int]] = set() # (idnum, generation) | ||
| d__ = cast( | ||
| "DictionaryObject", | ||
| self._reference_clone(self.__class__(), pdf_dest, force_duplicate), | ||
| self._reference_clone(self.__new__(self.__class__), pdf_dest, force_duplicate), | ||
| # self.__new__(self.__class__) because we want instance of type __class__, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments should go before, not after the code. |
||
| # where we copy values into later below | ||
| ) | ||
| if ignore_fields is None: | ||
| ignore_fields = [] | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| import pytest | ||
|
|
||
| from pypdf import PdfReader, PdfWriter | ||
| from pypdf.annotations._markup_annotations import Polygon | ||
| from pypdf.constants import AFRelationship | ||
| from pypdf.errors import PdfReadError, PyPdfError | ||
| from pypdf.generic import ( | ||
|
|
@@ -575,3 +576,27 @@ def test_embedded_file__order(): | |
| "test.txt", attachment4.pdf_object.indirect_reference, | ||
| "xyz.txt", attachment3.pdf_object.indirect_reference, | ||
| ] | ||
|
|
||
|
|
||
| def test_merge_page_with_annotation(): | ||
| # added and adapted from issue #3467 | ||
|
||
| writer = PdfWriter() | ||
| writer2 = PdfWriter() | ||
| writer.add_blank_page(100, 100) | ||
| writer2.add_blank_page(100, 100) | ||
|
|
||
| annotation = Polygon( | ||
| vertices=[(50, 550), (200, 650), (70, 750), (50, 700)], | ||
| ) | ||
|
|
||
| writer.add_annotation(0, annotation) | ||
|
|
||
| page1 = writer.pages[0] | ||
| page2 = writer2.pages[0] | ||
| page2.merge_page(page1) | ||
|
|
||
| assert page2.annotations[0].get_object()["/Type"] == annotation["/Type"] | ||
| assert page2.annotations[0].get_object()["/Subtype"] == annotation["/Subtype"] | ||
| assert page2.annotations[0].get_object()["/Vertices"] == annotation["/Vertices"] | ||
| assert page2.annotations[0].get_object()["/IT"] == annotation["/IT"] | ||
| assert page2.annotations[0].get_object()["/Rect"] == annotation["/Rect"] | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an explaining comment, not a docstring, thus please make it a "simple" comment. Are we able to re-use some of the values used here in the
__init__method?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what values do you mean? i would want
__init__to handle initialization of attribute because that is a python standard.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The values initialized to
Nonehere.