Question

I am wondering if it's possible to re-use an existing font that has already been embedded in a PDF. I ask this because when I add a font that I wish to use to the PDF, it looks like it has been added multiple times to the PDF file:

enter image description here

I can't seem to way to search for a font by it's name. I am embedding the font like so:

Doc theDoc = new Doc();
theDoc.Read("existing-pdf-file.pdf");
int FONT_MyriadPro = theDoc.EmbedFont("Myriad Pro");
theDoc.Font = FONT_MyriadPro;
theDoc.AddText("Example");

I note that the FONT_MyriadPro variable has value of 61, so I presume that it's possible to reference other existing fonts. But can I know what the font is? There doesn't seem to be any collection of fonts in the Doc object.

Was it helpful?

Solution

The document itself may contain different fonts. These are not accessible via the XFont.FindName method but you can find them by looking through the document ObjectSoup.

To a certain extent fonts in a document may be reused. However it is not uncommon to find fonts in a state where they cannot be sensibly reused. For example, font subsetting often removes crucial characters that you may wish to use.

In most cases it is just better to use a globally available font that you know is not going to have been mangled.

Later if you should wish to rationalize multiple font subset that may exist in the document you can use the ReduceSizeOperation to do so.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top