We use an old reporting software to create PDFs, but it is unable to embed the used fonts in the file.
Now I am trying to use iTextSharp to embed all (non-embedded) fonts in an existing PDF based on these examples EmbedFontPostFacto, ListUsedFonts and other information from other similar questions.
Like in the first example I create a fontfile for each font and then add it to the font object (PdfDictionary) or rather to the font descriptor.
// the font file
byte[] fontfile = null;
using (FileStream fs = new FileStream(
fontFileName, FileMode.Open, FileAccess.Read))
{
fontfile = new byte[fs.Length];
fs.Read(fontfile, 0, (int)fs.Length);
}
// create a new stream for the font file
PdfStream stream = new PdfStream(fontfile);
stream.FlateCompress();
stream.Put(PdfName.LENGTH1, new PdfNumber(fontfile.Length));
PdfDictionary desc = font.GetAsDict(PdfName.FONTDESCRIPTOR);
PdfIndirectObject objref = stamper.Writer.AddToBody(stream);
desc.Put(PdfName.FONTFILE2, objref.IndirectReference);
This (mostly) works, but since this embeds the entire font and not a subset, the files can get very big.
So I am wondering if there is a way to embed the fonts only as a subset retroactively, either with iTextSharp or any other way.
Any help is appreciated.