Skip to content
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

Allow add_link() to be called before add_page(). #1337

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

osresearch
Copy link

This patch sets the default page to 1 for add_link() if no pages have yet been added to the PDF, otherwise the default target is the current page. Page 1 is mandatory, so the target will definitely be valid even if it is not later pointed elsewhere with set_link().

Since this is no longer an error, the test/test_links.py test_inserting_link_with_no_page_number() has been changed to ensure that it produces the same document as the later test_later_call_to_set_link().

Checklist:

  • A unit test is covering the code added / modified by this PR

  • This PR is ready to be merged

  • In case of a new feature, docstrings have been added, with also some documentation in the docs/ folder

  • A mention of the change is present in CHANGELOG.md

By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.

@osresearch osresearch requested a review from gmischler as a code owner January 4, 2025 12:58
This patch sets the default page to 1 for add_link() if
no pages have yet been added to the PDF, otherwise the
default target is the current page.  Page 1 is mandatory,
so the target will definitely be valid even if it is not
later pointed elsewhere with set_link().

Since this is no longer an error, the test/test_links.py
test_inserting_link_with_no_page_number() has been changed
to ensure that it produces the same document as the later
test_later_call_to_set_link().
pdf.set_link(link_to_section1, page=pdf.page)
pdf.cell(text="Section 1: Bla bla bla")

assert_pdf_equal(pdf, HERE / "later_call_to_set_link.pdf", tmp_path)
Copy link
Member

@Lucas-C Lucas-C Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please provide the reference file later_call_to_set_link.pdf as part of this PR, please?

You just need to pass generate=True to this function call in order to generate it:
https://py-pdf.github.io/fpdf2/Development.html#generating-pdf-files-for-testing

You will also need to run black test/test_links.py in order to pretty-format this file.

@Lucas-C
Copy link
Member

Lucas-C commented Jan 6, 2025

@allcontributors please add @osresearch for code

Copy link

@Lucas-C

I've put up a pull request to add @osresearch! 🎉

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.

2 participants