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

The Return of the Embedded Font Issue #1346

Closed
TastyPi opened this issue Mar 25, 2024 · 15 comments
Closed

The Return of the Embedded Font Issue #1346

TastyPi opened this issue Mar 25, 2024 · 15 comments

Comments

@TastyPi
Copy link

TastyPi commented Mar 25, 2024

Prawn 2.5.0 appears to have reintroduced this old "Cannot extract the embedded font" issue prawnpdf/ttfunk#73

Using the exact same code to render a PDF using 2.4.0 does not have this issue.

@pointlessone
Copy link
Member

Do you experience this issue if you disable font subsetting?

@TastyPi
Copy link
Author

TastyPi commented Mar 25, 2024

I tried with subset: true and subset: false, both have the issue

@pointlessone
Copy link
Member

Could you please provide a minimal reproduction script and fonts you have issues with?

@pointlessone
Copy link
Member

pointlessone commented Mar 25, 2024

Also could you please list versions of the gems you use?

gem list --all --exact prawn ttfunk pdf-core

Or if you use bundler:

bundle list | grep -E 'prawn|ttfunk|pdf-core'

@TastyPi
Copy link
Author

TastyPi commented Mar 25, 2024

I tried a minimal example that just sets the font, but that did not reproduce the issue so it's definitely something deeper. Our PDF generation code is pretty complex, so it'll take me a while to create a minimal example, not sure when I'll find the time 😕.

Before downgrading (with issue):

bundle list | grep -E 'prawn|ttfunk|pdf-core'
  * pdf-core (0.10.0)
  * prawn (2.5.0)
  * ttfunk (1.8.0)

After downgrading (no issue):

bundle list | grep -E 'prawn|ttfunk|pdf-core'
  * pdf-core (0.9.0)
  * prawn (2.4.0)
  * ttfunk (1.7.0)

@TastyPi
Copy link
Author

TastyPi commented Mar 25, 2024

Thanks to the magic of Ruby, I've managed to log every call made to the Prawn::Document instance, and successfully reproduced the issue. I'm just cleaning it up to remove specific details and make it minimal.

@TastyPi
Copy link
Author

TastyPi commented Mar 25, 2024

Here we go, a minimal reproduction:

#!/usr/bin/env ruby

require "prawn"

pdf = Prawn::Document.new
pdf.font_families.update(
  "roboto" => {
    normal: "Roboto/Roboto-Regular.ttf",
    italic: "Roboto/Roboto-Italic.ttf",
    bold: "Roboto/Roboto-Bold.ttf",
    bold_italic: "Roboto/Roboto-BoldItalic.ttf",
  }
)
pdf.font("roboto")

pdf.text_box("€")

File.open("test.pdf", "w") do |file|
  pdf.render(file)
end

system "flatpak run com.adobe.Reader test.pdf"

I used Roboto here as an easy to acquire example, but it worked with another font I used. Seems to be an issue with the € symbol.

Even more curiously, this minimal example is also a problem with 2.4.0, though our full code is fine. So not sure what's going on there.

@TastyPi
Copy link
Author

TastyPi commented Mar 25, 2024

OK, it's a bug in ttfunk not prawn

The minimal example works with these versions:

gem "prawn", "2.4.0"
gem "ttfunk", "1.7.0"
gem "pdf-core", "0.9.0"

But breaks with these:

gem "prawn", "2.4.0"
gem "ttfunk", "1.8.0"
gem "pdf-core", "0.9.0"

i.e. the issue appears to be in ttfunk 1.8.0

prawn 2.5.0 requires ttfunk 1.8.0 so I haven't tested the prawn 2.5.0 ttfunk 1.7.0 combination to see if that works.

@pointlessone
Copy link
Member

Thanks.

@coorasse
Copy link

Thanks for the deep dive @TastyPi, you helped us!
Will you open an issue on ttfunk, or is the team aware of it?
We locked ttfunk gem 'ttfunk', '< 1.8.0' in the meantime.

@TastyPi
Copy link
Author

TastyPi commented Mar 27, 2024

Filed prawnpdf/ttfunk#102, I wasn't sure if @pointlessone was going to do it as they appear to be the main ttfunk developer.

@TastyPi TastyPi closed this as completed Mar 27, 2024
@pointlessone
Copy link
Member

It's not immediately obvious where the issue is. PDF has rather complex relationships with fonts. Fonts are partially represented/duplicated in native PDF structures, some essential parts (according to fonts specs) of fonts are ignored in PDF, renderers don't exactly follow specs (both PDF and fonts). So the issue might not be in TTFunk even if it's related to fonts. Let's keep it as is, I'll figure it out when I'll have time to work on this.

@Salman464
Copy link

Encountered the same error recently Cannot extract the embedded font '3a9d5f+Recoleta-Bold'. Some characters may not display or print correctly.

Faced issue on the versions:

  • pdf-core (0.10.0)
  • prawn (2.5.0)
  • ttfunk (1.8.0

Resolution:
Downgraded gems to resolve:

  • pdf-core (0.9.0) (automatically downgraded with prawn and ttfunk)
  • prawn (2.4.0)
  • ttfunk (1.7.0)

I can confirm that downgrading to previous versions of prawn and ttfunk resolved the issue. not sure though if the issue is from ttfunk or prawn upgrade

@afdev82
Copy link

afdev82 commented Jul 4, 2024

Do you experience this issue if you disable font subsetting?

I had the same error and I have "solved" it disabling the subsetting when registering the font family.
If I can inspect something to provide some help to solve the issue, let me know what I can do.
Thank you.

@timokleemann
Copy link

I can confirm that this Gem combination fixed the issue in my Rails 7 application:

gem "pdf-core", "0.9.0"
gem "prawn", "2.4.0"
gem "ttfunk", "1.7.0"

The special characters that were previously missing in Acrobat Reader are now visible again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants