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

ENH: Create /Font if not exists (#2670) #2671

Closed

Conversation

BrooksWatson717
Copy link

Updates the _writer.py to create the /DR and /Font dictionaries, and add a font (Helvetica) if they don't exist. This enables filling out PDF forms.

Response to issue #2670

Updates the _writer.py to create the /DR and /Font dictionaries, and add a font (Helvetica) if they don't exist. This enables filling out PDF forms.
pypdf/_writer.py Outdated Show resolved Hide resolved
@stefan6419846
Copy link
Collaborator

Thanks for the PR. Besides of the above remarks, could you please add a corresponding test as well?

- Added test
- Cleaned up code (simplified and fixed variable name)
Copy link

codecov bot commented May 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.01%. Comparing base (109ef4a) to head (aed6a28).
Report is 73 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2671   +/-   ##
=======================================
  Coverage   95.00%   95.01%           
=======================================
  Files          50       50           
  Lines        8356     8362    +6     
  Branches     1673     1674    +1     
=======================================
+ Hits         7939     7945    +6     
  Misses        259      259           
  Partials      158      158           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

I updated the SubType TrueType. I see some research saying that Type1 fonts are seeing declining support.

I didn't see any change in functionality, but figured it would be good to make the change regardless.
font_entry = DictionaryObject({
NameObject("/Type"): NameObject("/Font"),
NameObject("/Subtype"): NameObject("/TrueType"),
NameObject("/BaseFont"): NameObject("/Helvetica"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Couldn't we make the font name configurable through a constant or method parameter?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Helvetica is the default font that should be embedded in viewers

@@ -44,6 +44,29 @@
SAMPLE_ROOT = Path(PROJECT_ROOT) / "sample-files"
GHOSTSCRIPT_BINARY = shutil.which("gs")

def test_fill_form_without_font(pdf_file_path):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please do not add new tests at the top. Additionally: Where can I see that the new functionality is checked? Shouldn't we test with your example file as well which would previously raise an exception?

@pubpub-zz
Copy link
Collaborator

pubpub-zz commented May 26, 2024

I've proposed an alternative PR #2677

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.

3 participants