2
votes

I have a java application which splits a pdf into sections using itext, then stitches a selection of these up together again. The original pdf has many embedded fonts varying in type (all non-system fonts). When I stitch the pdf's up again, some of the embedded fonts are missing.

For example, this is a clipping from the original fonts list: enter image description here

This is a clipping from the generated pdf font list: enter image description here

I am using PdfWriter and PdfReader to copy the pages into the new document, with PdfContent and addTemplate().

1
iText doesn't change fonts when it's simply copying content from a PdfImportedPage. I suspect if you looked at a page-by-page breakdown of font usage, you'll find that they're correct. - Mark Storer
When the original pdf is split into sections, each section has the correct fonts intact for each page. But when they are stitched back into one whole pdf, certain pages do not display correctly because some of the fonts are not embedded any more. - Valerie

1 Answers

3
votes

Finally found the answer! The problem was the level of Pdf was set too low:

writer.setPdfVersion(PdfWriter.VERSION_1_2);

I changed this to:

writer.setPdfVersion(PdfWriter.VERSION_1_7);

and now all fonts are embedded correctly.

I actually forgot that piece of code was in there - I had borrowed it from a project I had done in the past.

Lesson learned ;)

I would love to know why this is the case though.