Blog post

Understanding fonts in PDFs: A comprehensive guide

Patrik Weiskircher Patrik Weiskircher
Illustration: Understanding fonts in PDFs: A comprehensive guide

Have you ever opened a PDF and noticed the text looks different from what you expected? Fonts play a crucial role in PDFs, significantly impacting a document’s presentation and readability. When fonts aren’t properly managed in PDFs, various challenges can arise, including rendering issues, loss of visual integrity, and potential miscommunication of content. Ensuring font availability and consistency is crucial for effective document sharing and collaboration, as it helps maintain a document’s intended appearance across different platforms.

Fonts in PDFs

There are two ways fonts can be referenced in a PDF: They can be embedded, or they rely on finding the font in the system of the user.

Embedded fonts are included directly within a PDF file. This ensures the document appears exactly as intended on any device, regardless of the fonts available on the user’s system. It also enhances document portability and visual consistency, as the embedded fonts are guaranteed to be available when the document is opened. Embedded fonts increase the file size of the PDF, but that can be mitigated by using font subsetting.

The PDF can also simply reference font files that are expected to be available on the user’s system. This can lead to issues if the font isn’t available, as the PDF viewer will substitute another font, potentially altering the document’s appearance. This approach reduces the file size of the PDF, but it can introduce inconsistencies in the document’s visual presentation. This is especially problematic when using a web-based PDF viewer, as the browser cannot access the system’s fonts.

Font subsetting

Font subsetting is a technique used in PDF creation to optimize file size by including only the necessary characters from a font. This process involves selecting specific glyphs that are actually used in the document, rather than embedding the entire font file. By doing so, font subsetting reduces the overall size of the PDF, making it more efficient for storage and sharing, while maintaining the essential visual elements required for proper document rendering.

When adding text using our SDKs, by default, we only include the characters that are actually used in the text. This ensures the PDF file size is kept to a minimum, while still ensuring the text is displayed correctly.

Nutrient SDKs and fonts

By default, Nutrient tries to embed the fonts used in the PDF, using font subsetting whenever possible. Sometimes, however, we have to rely on system fonts. For example, Nutrient Web SDK runs completely in the browser and cannot access a system’s fonts. In this case, we add a reference to the system font, which can lead to inconsistencies in the document’s appearance when opened in other readers. There are multiple ways of solving this.

Custom fonts

Our SDKs offer the ability to supply custom fonts to the PDF renderer, which can be used to ensure consistent rendering across different platforms. For more information, refer to the following platform-specific guides:

We treat custom fonts the same way we treat system fonts: They’re available for rendering the PDF itself, and they’re also used when text is added — for example, in text annotations or when filling out a form.

Dynamic font loading

For Nutrient Web SDK without Document Engine, dynamic font loading can be used. This loads fonts on demand when adding text and ensures that if you enter text in a language that requires a specific font, that font is loaded and used for rendering the text. This can be especially useful when dealing with a large number of fonts, as it avoids loading all fonts upfront, which can slow down the initial loading time of the viewer.

This isn’t yet used when rendering the page text itself, but we have plans to add it in the future.

Conclusion

Effective font management in PDFs is crucial for maintaining document quality and ensuring clear communication. This article explored the differences between embedded and system fonts and discussed the benefits of font subsetting and the importance of custom fonts for consistent rendering across platforms. By understanding these concepts and implementing best practices for font management, you can enhance the visual integrity and readability of your PDF documents, ensuring a seamless viewing experience for all users.

FAQ

Why do my PDFs look different on different devices? This usually happens because the PDF is referencing system fonts that may not be available on all devices. When a font is missing, the PDF viewer substitutes a different font, which can change the document’s appearance. Embedding fonts or using custom fonts can help maintain consistency.
How can I make sure my PDFs look the same on all platforms? To ensure consistent rendering across devices, use embedded fonts in your PDFs. Our SDKs embed fonts by default and use font subsetting to optimize file size while preserving the intended visual design.
Why is my PDF file size larger when using custom fonts? When you embed fonts in a PDF, the file size increases because the font data is included within the document. However, our SDKs use font subsetting to include only the characters used, significantly reducing the file size while maintaining proper rendering.
Can I use my own fonts in the Nutrient SDK? Yes! All our SDKs allow you to provide custom fonts. These fonts will be used for rendering and for adding text annotations or filling out forms.
Why does my text appear differently in the Web PDF viewer? The Web SDK cannot access system fonts, so if a font isn’t embedded, it may be substituted with a different one. You can use our custom font loading feature to ensure your fonts are correctly applied.
How can I optimize font usage in my PDFs to reduce file size? You can enable font subsetting, which includes only the characters used in the document rather than the entire font file. This reduces the file size while preserving the intended appearance.
What happens if my PDF references a font that isn’t available? If a PDF references a font that isn’t available on the user’s device and the font isn’t embedded, the PDF viewer will substitute another font. This can lead to layout changes and visual inconsistencies.
Author
Patrik Weiskircher
Patrik Weiskircher Core Team Lead

Patrik is the team lead of the Core Team, which oversees the shared codebase between our products. He knows far too many things about PDFs — ask him about fonts!

Free trial Ready to get started?
Free trial