Skip to content

Commit a722d45

Browse files
committed
ENH: Automatically preserve links in added pages
1 parent 0e70ef4 commit a722d45

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

pypdf/_writer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@
9494
DecodedStreamObject,
9595
Destination,
9696
DictionaryObject,
97+
DirectReferenceLink,
9798
EmbeddedFile,
9899
Fit,
99100
FloatObject,
100101
IndirectObject,
102+
NamedReferenceLink,
101103
NameObject,
102104
NullObject,
103105
NumberObject,

pypdf/generic/_link.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
# POSSIBILITY OF SUCH DAMAGE.
2626

2727

28-
# This module contains code used by _writer.py to track links in pages
29-
# being added to the writer until the links can be resolved.
28+
# This module contains classes used by _writer.py to track links in
29+
# pages being added to the writer until the links can be resolved.
3030

3131
from typing import TYPE_CHECKING, List, Optional, Tuple, Union, cast
3232

tests/test_merger.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,11 @@ def test_named_ref_to_page_that_is_gone(pdf_file_path):
505505
source = PdfReader(BytesIO(get_data_from_url(name="named-reference.pdf")))
506506
buf = BytesIO()
507507
tmp = PdfWriter()
508-
tmp.add_page(source.pages[2]) # we add only the page with the reference
508+
tmp.add_page(source.pages[2]) # we add only the page with the reference
509509
tmp.write(buf)
510510

511511
source = PdfReader(buf)
512512

513513
writer = PdfWriter()
514-
writer.add_page(source.pages[0]) # now references to non-existent page
515-
writer.write(pdf_file_path) # don't crash
514+
writer.add_page(source.pages[0]) # now references to non-existent page
515+
writer.write(pdf_file_path) # don't crash

0 commit comments

Comments
 (0)