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

Switch pdfrw to pypdf #169

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Switch pdfrw to pypdf #169

wants to merge 3 commits into from

Conversation

PJBrs
Copy link
Contributor

@PJBrs PJBrs commented Aug 23, 2024

This PR has three patches that improve pdf handling in the absence of pdftk. This lays some further groundwork for getting rid of pdftk in the future, and it gets rid of pdfrw now.

The first patch adds fallback merging separate pdfs with pypdf. The second patch moves fallback pdf filling code from pdfrw to pypdf. The last patch silences a (harmless) warning from the fillable personality sheet.

The pdfrw code for filling a pdf form contained a bug as well, which is fixed with this PR.

Without pdftk, dungeon-sheets was not able to merge the various
files produced by the fillable pdf forms. This patch adds a
function that uses pdfrw to merge to pdfs.
Switch the fallback function to fill pdf forms to pypdf.
Pypdf has a simpler interface for form filling and appears
to be somewhat more robust that pdfrw. Also, this yields
pdfs in version 1.7 instead of 1.3, and it eliminates a
dependency on pdfrw. Finally, the pdfrw code appeared to
be buggy:

fill_pdf_template.py, line 454, in _make_pdf_pdfrw
    this_field = annot[FIELD][1:-1]
TypeError: 'NoneType' object is not subscriptable

Unfortunately, this patch is not able to flatten pdfs,
since this functionality isn't implemented in pypdf
(it isn't implemented in pdfrw either).

This is a bugfix (no issue reported).
When filling forms with pypdf, the old blank
personality sheet gave the following error:

Font dictionary for /Helvetica not found.

This patch uses the blank personality sheet
split out from the current WotC fillable
character sheet, with an added pdf bookmark.
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.

1 participant