-
Notifications
You must be signed in to change notification settings - Fork 263
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
base: master
Are you sure you want to change the base?
Conversation
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().
392bd6e
to
35efe39
Compare
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) |
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.
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.
@allcontributors please add @osresearch for code |
I've put up a pull request to add @osresearch! 🎉 |
Hi @osresearch 🙂 Are you planning to finish this PR, following the feedback I gave you last month? |
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/
folderA 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.