pdflib-syntax-fonts

Embed TTF/OTF fonts with fontkit to prevent WinAnsi encoding failures in pdf-lib.

1|Updated Mar 19, 2026
One-click install
npx skills add https://github.com/OpenAEC-Foundation/pdf-lib-Claude-Skill-Package --skill pdflib-syntax-fonts
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pdflib-syntax-fonts
Source: https://github.com/OpenAEC-Foundation/pdf-lib-Claude-Skill-Package/tree/main/skills/source/pdflib-syntax/pdflib-syntax-fonts
Command: npx skills add https://github.com/OpenAEC-Foundation/pdf-lib-Claude-Skill-Package --skill pdflib-syntax-fonts

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Prevents runtime failures and incorrect rendering caused by using pdf-lib standard fonts for text that contains characters outside the WinAnsi subset, and guides correct embedding of custom fonts so Unicode, CJK, and other scripts render reliably.

Core Features & Use Cases

  • Correct Font Embedding: Explains when to use StandardFonts, embedStandardFont, and when to register fontkit and embed custom TTF/OTF bytes.
  • Unicode and Script Support: Shows how to use fontkit with custom fonts to render Cyrillic, CJK, Arabic, emoji, and other non-WinAnsi characters.
  • Text Measurement & Subsetting: Covers measurement methods, centering and alignment patterns, and subsetting decisions to balance file size and editability.
  • Anti-Patterns and Fixes: Lists common runtime errors (WinAnsi encoding, missing registerFontkit, forgetting await) and concrete fixes for production workflows.

Quick Start

Register fontkit, await embedding of a Unicode-capable font file, and use the resulting PDFFont to draw and measure text so non-Latin characters render without WinAnsi errors.

Frequently Asked Questions about pdflib-syntax-fonts

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does pdf-lib throw a WinAnsi encoding error when I try to render non-Latin characters?

pdf-lib throws a WinAnsi encoding error because standard fonts only support a limited Latin character set. To fix this, you must register fontkit and embed a custom TTF or OTF font that includes the required Unicode glyphs.

How do I embed custom TTF or OTF fonts in pdf-lib to support Unicode text?

To embed custom fonts in pdf-lib for Unicode support, call pdfDoc.registerFontkit(fontkit) first, then await pdfDoc.embedFont with your TTF or OTF font bytes. This ensures non-Latin scripts render correctly without encoding errors.

What is the difference between embedFont and embedStandardFont in pdf-lib?

embedStandardFont synchronously embeds built-in standard fonts limited to WinAnsi characters, while embedFont asynchronously embeds custom byte-based TTF or OTF fonts using fontkit to support full Unicode and CJK character sets.

How do I measure text width and subset fonts in pdf-lib to optimize file size?

You can measure text for alignment using the resulting PDFFont measurement methods after embedding. To optimize file size, apply font subsetting when embedding custom fonts, balancing reduced file size with text editability constraints.

Do I need to call registerFontkit before embedding byte-based fonts in pdf-lib?

Yes, you must call pdfDoc.registerFontkit(fontkit) before embedding byte-based TTF or OTF fonts. Without registering fontkit, pdf-lib cannot process custom font bytes or extract character sets for non-Latin text rendering.

Can I update PDF form field appearances with custom fonts in pdf-lib?

Yes, you can update form field appearances using custom embedded fonts in pdf-lib. Ensure you register fontkit and embed a Unicode-capable TTF or OTF font so special characters in form fields render without WinAnsi failures.