1

I am trying to make the code at PDFA tutorial work by adapting it to Groovy, and as soon as I add some content to my PDF I get a PdfAConformanceError

All the fonts must be embedded. This one isn't. Helvetica

Should the tutorial help me here or am I just supposed to already know what to do? As I am not sure I do, what would be the best method?

john renfrew
  • 393
  • 1
  • 9
  • 30
  • 1
    You can only make the tutorial work if you *embed* the font. You are not providing the Helvetica font program (iText ships with the AFM file, but you need the PFB file). Why don't you use FreeSans as is done in the tutorial? See also http://developers.itextpdf.com/question/why-do-i-get-font-embedding-error-when-creating-pdfa1a – Bruno Lowagie Dec 13 '15 at 15:21
  • My error... I had an incorrect path to the font file, so rather than giving an exception for that, it was trying to use Helvetica, which I had not provided either.. – john renfrew Dec 13 '15 at 15:27

1 Answers1

3

As the example shows, you have to make sure all fonts are embedded.

Create an embedded font:

Font bold10 = FontFactory.getFont(
    "./src/main/resources/com/itextpdf/FreeSansBold.ttf",
    BaseFont.WINANSI, BaseFont.EMBEDDED, 10);

Add content using that embedded font:

document.add(new Paragraph("Invoice number: " + invoice.getNumber(), bold10));

Note that Helvetica is the default font in iText, but the font program is not included. It is typically also not available on Windows systems. This is because of licensing.

Even if you have a font program available, you have to make sure that you are allowed to distribute it by embedding it in a PDF file.

rhens
  • 4,791
  • 3
  • 22
  • 38