Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Itext embed font in a PDF

I have a pdf that has been created using the Foxit form designer. On my design system, I have the barcode font installed. The barcode font is used in one of the AcroFields. It appears that foxit does not embed the font in the document.

I also have customers that do not have the barcode font installed in their computers, and thus I would like to embed the font into the PDF. Is there a way for me to embed a font that is used in the AcroFields into the PDF using iText?

EDIT: The font seems to be included in the text, but not the fields, Therefore the font(barcode) will not print.

like image 886
Milhous Avatar asked Mar 09 '09 15:03

Milhous


People also ask

Can you embed a font in a PDF?

To embed the fonts that are not already embedded, go to File > Print. Bring up the Adobe PDF settings and properties, then Adobe PDF settings. Embed your font. Edit the default settings and navigate to Font, click the Embed all fonts option.

Does PDF automatically embed fonts?

How to embed a font in a PDF. If you are using Adobe Acrobat to create your PDF then the latest versions will automatically embed any suitable fonts. In earlier versions you can turn this on or off, so make sure you have this ticked (see the diagram below).

Does Microsoft Word embed fonts in PDF?

1) In Word, under Adobe PDF, choose 'Change Conversion Settings'. 2) Click on the 'Advanced Settings' button. 3) Choose the 'Fonts' folder at the upper left. 4) Next, do two things: First, check the checkbox labeled 'Embed all fonts'.

How do I embed a missing font in a PDF?

Go to Tools > Print Production > Preflight select the “PDF fixups” option and select “Embed missing fonts” and click the “Analyze and fix” button to embed any unembedded fonts. After clicking Analyze and fix, you will be asked to save your new PDF document. Save it with the name and location you like.


1 Answers

I'm almost sure that you got an answer by now, but maybe others would like to get a detailed view on the solution. Below is the sample java code I used to embed fonts in the generated PDF (useful only in some cases, as the size of the documents increases dramatically). As a free tool to create the PDF forms, I have used the OpenOffice writer, by adding forms inside the documents and exporting the documents as PDF files :

PdfReader pdfTemplate = new PdfReader(templateName);
ByteArrayOutputStream out = new ByteArrayOutputStream();
BaseFont unicode = BaseFont.createFont(unicodeFontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
PdfStamper stamper = new PdfStamper(pdfTemplate, out);
//assigning the font to the field
stamper.getAcroFields().setFieldProperty("myField", "textfont", unicode, null);
stamper.getAcroFields().setField("myField", someValue);
stamper.close();
pdfTemplate.close();
like image 119
work.paul Avatar answered Oct 22 '22 03:10

work.paul