How do I subset a font using only the Adobe PDF Library?
Estimated Reading Time: 1 MinutesIn the Adobe Samples directory, the FontEmbed sample illustrates both embedding and subsetting a font.
The difficult part is creating the font. You must use one of the font creation methods that include the PDEFontCreateFlags:
- PDEFontCreateFromSysFont()
- PDEFontCreateFromSysFontAndEncoding()
- PDEFontCreatefromSysFontWithParams
The Flags kPDEFontCreateEmbedded and kPDEFontWillSubset must be on. You cannot, of course, subset if you do not embed. A font must be embedded in the PDF document first, and then it will be subset, where characters that are not needed are removed from that embedded font.
After all the type is set using this font, you must call PDEFontSubsetNow() to create the subset font, and PDEFontEmbedNow() to insert the font subset into the document.
If you are in an environment where some fonts may need to be embedded and subset, and others not, you may use the method PDEFontGetCreateNeedFlags() to test whether a given font needs to be subset or embedded.