Why do I get a font embedding error when creating PDFA/1a?
I have a class given below which is giving me Exception:
Exception in thread "main" com.itextpdf.text.DocumentException: com.itextpdf.text.pdf.PdfAConformanceException: All the fonts must be embedded. This one isn't: ZapfDingbats
I have the ZapfDingbats
font embedded but I am still getting this Exception
. What i am trying to achieve here is create a list
with a bullet
in front of every item
in the list
. What am i missing here?
public class SquareBullet { public static void main(String[] args) throws IOException, DocumentException, XMPException { Document document = new Document(); PdfAWriter writer = PdfAWriter.getInstance(document, new FileOutputStream("list.pdf"), PdfAConformanceLevel.PDF_A_1A); writer.setViewerPreferences(PdfAWriter.PageModeUseOutlines); writer.setRunDirection(PdfAWriter.RUN_DIRECTION_LTR); writer.setTagged(PdfAWriter.markAll); writer.createXmpMetadata(); XmpWriter xmp = writer.getXmpWriter(); DublinCoreProperties.addSubject(xmp.getXmpMeta(), "Subject"); DublinCoreProperties.setTitle(xmp.getXmpMeta(), "Title", "en_US", "en_US"); DublinCoreProperties.setDescription(xmp.getXmpMeta(), "Description", "en_US", "en_US"); PdfProperties.setKeywords(xmp.getXmpMeta(), "Keywords"); PdfProperties.setVersion(xmp.getXmpMeta(), "1.4"); document.addLanguage("en_US"); document.open(); Font font = FontFactory.getFont(FontFactory.ZAPFDINGBATS, BaseFont.ZAPFDINGBATS, BaseFont.EMBEDDED, 12); Font font1 = FontFactory.getFont(FontFactory.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED, 12); ICC_Profile icc = ICC_Profile.getInstance(new FileInputStream("sRGB Color Space Profile.icm")); writer.setOutputIntents("Custom", "", "https://www.color.org", "sRGB IEC61966-2.1", icc); List list = new List(10); list.setListSymbol(new Chunk(String.valueOf((char)110), font)); list.add(new ListItem(new Chunk("Test 1", font1))); list.add(new ListItem(new Chunk("Test 2", font1))); list.add(new ListItem(new Chunk("Test 3", font1))); document.add(list); document.close(); } }
Your claim I have the ZapfDingbats font embedded is wrong.
Granted, you define the font like this:
Font font = FontFactory.getFont(FontFactory.ZAPFDINGBATS,
BaseFont.ZAPFDINGBATS, BaseFont.EMBEDDED, 12);
As you use BaseFont.EMBEDDED
, you might assume that the font will be embedded, but it isn't. You can check this by using that font in any other PDF that isn't PDF/A: if you go to Document Properties > Fonts, you'll see that the font isn't embedded.
Why is this?
There are 14 special fonts in PDF. We refer to them as the Standard Type 1 fonts. Every PDF viewer should be able to render text that uses those fonts, hence these fonts don't need to be embedded: 4 Helvetica fonts (regular, bold, italic, bold-italic), 4 Times Roman fonts (regular, bold, italic, bold-italic), 4 Courier fonts (regular, bold, italic, bold-italic), Symbol and Zapfdingbats.
iText ships with the AFM files of these fonts. AFM stands for Adobe Font Metrics and the files contain data about the widths, bounding boxes, and other metrics of glyphs that are available in each font.
The actual description of the shape of these fonts isn't shipped with iText. These are stored in a PFB (Printer Font Binary) file. Without these PFB files, iText can't (and won't) embed these Standard Type 1 fonts.
In other words: iText ignores the BaseFont.EMBEDDED
parameter.
This is documented on many places. If you want to create PDF/A, you need font files, such as TTF, OTF, TTC files, or a combination of AFM and PFB files.