
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.