Erhard Schwenk
Erhard Schwenk

Reputation: 21

creating PDF/A-1b without needing a Helvetica Font file

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?

Upvotes: 2

Views: 4473

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

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.

Upvotes: 1

Related Questions