Skip to content

Fix missing 'g's from PDFs#5227

Merged
awwaiid merged 2 commits into
rubyforgood:mainfrom
Sukhpreet-s:5198-font-issue-missing-gs
Jun 16, 2025
Merged

Fix missing 'g's from PDFs#5227
awwaiid merged 2 commits into
rubyforgood:mainfrom
Sukhpreet-s:5198-font-issue-missing-gs

Conversation

@Sukhpreet-s

Copy link
Copy Markdown
Contributor

Resolves #5198

Description

This PR fixes the issue of missing 'g's in PDFs downloaded through the web app, specifically when opened using Adobe Acrobat Reader.

This is fixed by downgrading and pinning the ttfunk gem. The prawn gem is also pinned to a lower version to satisfy ttfunk requirements, and also to stop it from downgrading too much (0.8.4).

Updates to the gem versions:

  • prawn: from 2.5.0 to 2.4.0
  • ttfunk: from 1.8.0 to 1.7.0

There is already an ongoing discussion about this issue on the ttfunk repo. The downgrade fix was suggested in one of the comments.

Notes

I tested this issue using the following PDF viewers:

The issue only appeared when using Adobe, and every other PDF reader rendered it correctly.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

This is tested manually by downloading and opening a PDF with Adobe Acrobat Reader to ensure the g's are there.

Screenshots

Before

After fix

@cielf

cielf commented Jun 5, 2025

Copy link
Copy Markdown
Collaborator

Will take a look at this tomorrow

@cielf

cielf commented Jun 6, 2025

Copy link
Copy Markdown
Collaborator

Looks good functionally. @dorner -- as a standard, should we put a more specific comment so we can later guess that it might be ok to remove the specificity (As for myself, I have no idea what would break if we updated the other gems that are in the "for compatability reasons" group )

@cielf cielf requested a review from dorner June 6, 2025 17:32
@dorner

dorner commented Jun 6, 2025

Copy link
Copy Markdown
Collaborator

@Sukhpreet-s tests are failing unfortunately.

@Sukhpreet-s

Sukhpreet-s commented Jun 6, 2025

Copy link
Copy Markdown
Contributor Author

@Sukhpreet-s tests are failing unfortunately.

I probably did local testing on the main branch accidentally, instead of testing in the feature branch. Oopsie 😅

I'll look into it. Thanks for pointing it out!

@Sukhpreet-s

Copy link
Copy Markdown
Contributor Author

The test at ./spec/system/adjustment_system_spec.rb:89 is failing, but it passed for me in Codespaces on the feature branch ✅ -- possibly a flaky test?


The other failures in ./spec/pdfs/distribution_pdf_spec.rb seem to be due to PDF fixture mismatches. The visual output is unchanged, but PDF encoding differences (likely from gem version changes) are causing the failures.

I followed the instructions in the code comments to regenerate the fixture PDFs using bundle exec rails console --sandbox,

# Run the following from Rails sandbox console (bin/rails/console --sandbox) to regenerate these comparison PDFs:
# => load "lib/test_helpers/pdf_comparison_test_factory.rb"
# => Rails::ConsoleMethods.send(:prepend, PDFComparisonTestFactory)
# => PDFComparisonTestFactory.create_comparison_pdfs

but the tests still fail -- even when regenerated on the main branch. If anyone has insight into why the encoding differences persist, it would be helpful.

@dorner

dorner commented Jun 11, 2025

Copy link
Copy Markdown
Collaborator

Are they consistently different? If you regenerate them again, do they stay the same? I'm wondering if there's something on your machine that generates them differently than on CI.

@Sukhpreet-s

Copy link
Copy Markdown
Contributor Author

Further investigated...

I found that the PDF comparison mismatch does not happen when using the 3.2.2 Ruby version. It happened when I had 3.4.3 as the active Ruby version and ran bin/setup. Then the PDF created using rails console and tests in rspec doesn't match.

Also, I found that there's some visual differences as well as shown in the side-by-side screenshot below. The main differences are in the table.

  • Left is generated by rspec test.
  • Right is generate by running PDFComparisonTestFactory.create_comparison_pdfs in rails console
    image

Here is a part of diff between the 2 PDFs generated by the above ways:

# line 20
- << /Length 9745
+ << /Length 10232

#line 156. there's multiple of these types of changes.
/DeviceRGB cs
0.86667 0.86667 0.86667 scn
- 36.0 460.959 190.0 21.759 re
+ 36.0 452.407 190.0 21.759 re

# At the end of the file
>>
startxref
- 37363
+ 37851

@Sukhpreet-s

Copy link
Copy Markdown
Contributor Author

Are they consistently different? If you regenerate them again, do they stay the same? I'm wondering if there's something on your machine that generates them differently than on CI.

Every time I generate the fixture PDFs, they are the same.

One thing to note is that I'm not running Rails::ConsoleMethods.send(:prepend, PDFComparisonTestFactory) when generating these PDFs because Rails::ConsoleMethods is deprecated, and I'm not sure how that affects this.

@Sukhpreet-s

Copy link
Copy Markdown
Contributor Author

As discussed in the weekly meeting today, @awwaiid mentioned this PDF conflict was due to missing Flipper.enable(:enable_packs) in the tests. Now it's added to run before each test that compares distribution PDFs.

✨ Thank you @awwaiid and @cielf for helping figure this out! ✨

@awwaiid awwaiid left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great, thank you!

@awwaiid awwaiid merged commit 2887a0d into rubyforgood:main Jun 16, 2025
11 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

@Sukhpreet-s: Your PR Fix missing 'g's from PDFs is part of today's Human Essentials production release: 2025.06.29.
Thank you very much for your contribution!

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.

Font issue -- further investigation and fix

4 participants