asciidoctor / asciidoctor-pdf

:page_with_curl: Asciidoctor PDF: A native PDF converter for AsciiDoc based on Asciidoctor and Prawn, written entirely in Ruby.
https://docs.asciidoctor.org/pdf-converter/latest/
MIT License
1.14k stars 501 forks source link

Unable to embed fonts in PDF #2420

Closed mraible closed 1 year ago

mraible commented 1 year ago

The latest version of my JHipster Mini-Book fails to upload to Lulu because of an error about embedded fonts. InfoQ tried to use the original "prepress" file, and it doesn’t work, saying that some fonts aren’t embedded. You can download this file from https://github.com/mraible/jhipster-book/releases/tag/v7.0.0.

234643598-974c7699-414f-495d-ba40-158625815ed6

I haven't had this problem with previous releases.

Would y'all happen to know how to fix this so it properly uploads to Lulu?

Related: https://github.com/mraible/jhipster-book/issues/111

mojavelinux commented 1 year ago

I'm unaware of any changes to how Prawn embeds fonts. It's possible this is a new validation on the Lulu side, perhaps one that is not interpreting the embedded fonts correctly. What I can tell you is that there's no mode in which fonts are not embedded. If they are being used in the PDF, they are embedded.

mojavelinux commented 1 year ago

If you see this:

WARNING: Could not locate the character `█' in the following fonts: M+ 1mn, M+ 1p Fallback, Emoji

What that means is that the font that provides that character is missing and thus there is no font to back up the use of that character. I could see how Lulu would complain in this case that there is no font available to render the glyph for that character.

mojavelinux commented 1 year ago

When running this on Asciidoctor PDF 2.3.7, the problem is very clear:

asciidoctor: WARNING: Could not locate the character `⬢' (\u2b22) in the following fonts: Noto Serif, M+ 1p Fallback, Noto Emoji

The glyph for the character \u2b22 is not provided by Noto Emoji (or any other font). Therefore, it ends up being a missing glyph. That's what Lulu is complaining about. You either need to remove the emoji from the AsciiDoc document or provide a font that includes the glyph for this character (though I'm enable to quickly find one).

In the future, please ask questions about debugging and usage to the project chat at https://chat.asciidoctor.org.

mraible commented 1 year ago

Thanks, @mojavelinux! I added some if statements for PDFs around lines with emojis. For example:

ifndef::backend-pdf[]
🚀 Welcome to the JHipster CI/CD Sub-Generator 🚀
endif::[]
ifdef::backend-pdf[]
Welcome to the JHipster CI/CD Sub-Generator
endif::[]
mojavelinux commented 1 year ago

That will certainly do the trick.

Another idea to reduce repetition is to put the emoji in an attribute. Then you only need the ifdef around the attribute definition. After that, you just refer to the attribute value using an attribute reference. Since you sometimes need a space before or after, you might need two attributes.