Skip to content

Commit ed4f76d

Browse files
authored
Preserve link annotations during FPDF.multi_cell(..., dry_run=True) (#1808)
* add tests for dry run link annotations bug * Fix dry run link annotations bug * note fix in change log * fix position of text on pdf page
1 parent 7bc5603 commit ed4f76d

4 files changed

Lines changed: 49 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This can also be enabled programmatically with `warnings.simplefilter('default',
2424
* preserve boundary-neutral formatting during bidirectional text preprocessing - _cf._ [issue #1779](https://github.com/py-pdf/fpdf2/issues/1779)
2525
* transform application on user space gradients - _cf._ [issue #1784](https://github.com/py-pdf/fpdf2/issues/1784)
2626
* dependency extras for camelot-py and endesive on pyproject.toml - _cf._ [issue #1792](https://github.com/py-pdf/fpdf2/issues/1792)
27+
* preserve link annotations during dry-run of pdf.multi_cell - _cf._ [issue #1807](https://github.com/py-pdf/fpdf2/issues/1807)
2728
### Changed
2829
* skip byte-for-byte compressed data comparison when zlib-ng is detected, regardless of OS
2930

fpdf/fpdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4686,7 +4686,7 @@ def _disable_writing(self) -> Iterator[None]:
46864686
self.x,
46874687
self.y,
46884688
)
4689-
annots = self.pages[self.page].annots or PDFArray()
4689+
annots = PDFArray(self.pages[self.page].annots or [])
46904690
self._push_local_stack()
46914691
try:
46924692
yield
1.58 KB
Binary file not shown.

test/text/test_multi_cell_markdown.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,50 @@ def test_multi_cell_markdown_link(tmp_path):
147147
markdown=True,
148148
)
149149
assert_pdf_equal(pdf, HERE / "multi_cell_markdown_link.pdf", tmp_path)
150+
151+
152+
def test_multi_cell_markdown_link_dry_run(tmp_path):
153+
pdf = fpdf.FPDF()
154+
pdf.set_font("Helvetica")
155+
pdf.add_page()
156+
assert len(pdf.pages[1].annots) == 0
157+
158+
pdf.multi_cell(
159+
pdf.epw,
160+
text="**Start** [One Page Dungeon Context](https://www.dungeoncontest.com/) __End__",
161+
dry_run=True,
162+
markdown=True,
163+
new_x="left",
164+
new_y="next",
165+
)
166+
assert len(pdf.pages[1].annots) == 0
167+
168+
pdf.multi_cell(
169+
pdf.epw,
170+
text="**Start** [One Page Dungeon Context](https://www.dungeoncontest.com/) __End__",
171+
markdown=True,
172+
new_x="left",
173+
new_y="next",
174+
)
175+
assert len(pdf.pages[1].annots) == 1
176+
177+
pdf.multi_cell(
178+
pdf.epw,
179+
text="**Start** [One Page Dungeon Context](https://www.dungeoncontest.com/) __End__",
180+
dry_run=True,
181+
markdown=True,
182+
new_x="left",
183+
new_y="next",
184+
)
185+
assert len(pdf.pages[1].annots) == 1
186+
187+
pdf.multi_cell(
188+
pdf.epw,
189+
text="**Start** [One Page Dungeon Context](https://www.dungeoncontest.com/) __End__",
190+
markdown=True,
191+
new_x="left",
192+
new_y="next",
193+
)
194+
assert len(pdf.pages[1].annots) == 2
195+
196+
assert_pdf_equal(pdf, HERE / "multi_cell_markdown_link_dry_run.pdf", tmp_path)

0 commit comments

Comments
 (0)