2

I need to create some simple but PDF/A-1b conform PDF-Files using iText.

My first approach looks like this:

Document document = new Document(Pagesize.A4); 
ByteArrayOutputStream pdfBuffer = new ByteArrayOutputStream); 

PdfAWriter pdfAWriter 
  = PdfAWriter.geInstance (document, pdfBuffer, PdfAConformanceLevel.PDFA_1B);
pdfAWriter.createXmpMetadata();

Font fixedFont = FontFactory.getFont("Courier New", BaseFont.CP1252, BaseFont.EMBEDDED, 10, Font.NORMAL); 

document.open();

Chunk chunk = new Chunk("Hello World", fixedFont);
Paragraph paragraph = new Paragraph(chunk); 
document.add(paragraph);  

document.close();

// this is pseudo code to transfer the Buffer to a real file
writeByteArrayToFile(pdfBuffer.toByteArray());

Thos Code generates an Error Message:

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

Looking around I found out that Helvetica is the default Document Font of iTextn which cannot be changed, that this is a Base PDF Font which is not embedded by default and that I can only embed it if I have a Helvetica pfb or ttf File (which I do not have and do not want to buy since I am not planning to use that font at all in my documents).

There is no need for any Helvetica Text in my PDF at all. I need to generate PDF/A-1b which requires to embed all fonts including the PDF Base Fonts.

So is this a Bug? What is the correct Way to generate a PDF/A with iText if there is no Helvetica Font file available?

  • That is the normal behavior. If you cannot add the font to the pdf just replace that font. – rekire Jan 22 '15 at 14:22
  • I suspect that you have not registered the fonts and what FontFactory is returning is the default font that happens to be Helvetica. – Paulo Soares Jan 22 '15 at 15:05
  • Could you take a look at the question https://stackoverflow.com/q/52736441/3169868 – S_S Oct 10 '18 at 11:59

1 Answers1

1

My first reaction would be in line with the comment made by @rekire: This is a very strange question. One of the imperative requirements of a PDF/A file is that you embed every font. Now you are asking for a PDF/A document without embedding a font such as Helvetica. That would be a document without any text.

You did not respond to this reaction, but a possible reply could be: if you look at my code, you clearly see that I am not using Helvetica, I am using "Courier New". Why do I need Helvetica if I use Courier New?

That's my second reaction: You are not using Courier New! This line is not sufficient:

Font fixedFont = FontFactory.getFont("Courier New", BaseFont.CP1252, BaseFont.EMBEDDED, 10, Font.NORMAL);

I don't see you registering courier.ttf anywhere. Hence iText does not know where to find Courier New. It uses Helvetica instead. When I consult The Best iText Questions on StackOverflow (a book I can highly recommend), I find the following questions:

The answers to these questions explain what is going wrong in your example. Note that you'll find some complete PDF/A examples in the sandbox on the official iText site.

Community
  • 1
  • 1
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165