Skip to main content
Known Participant
December 14, 2022
Question

embedding and using font at document level

  • December 14, 2022
  • 3 replies
  • 1312 views

 

I am using a font that allows embedding, which I need to do to make the document truly portabe (so people can see characters from a custom font without having it installed). I was using the code at the bottom of this message. The issue is that it is embedding the font every time I write something. I looked for fuctions to embed it once at the document level and then find and use it if there (or embed if not), but it is not at all obvious to me what those functions might be.

PDSysFont sysFont = PDFindSysFont(&pdeFontAttrs, sizeof(PDEFontAttrs), 0);
// Get the font attributes.
PDSysFontGetAttrs(sysFont, &pdeFontAttrs, sizeof(pdeFontAttrs));
// Create the PDE font from the system font.
// Check the font embedding bits for preview and print, or editing.
// Based on the font embedding bits, decide whether to embed or subset
// the font.
PDEFont pdeFont = NULL;
ASUns32 fontCreateFlags;
if ((pdeFontAttrs.protection & kPDEFontNoEditableEmbedding) == 0)
{
// Editing OK. Embed the entire font.
fontCreateFlags = kPDEFontCreateEmbedded;
}
else if ((pdeFontAttrs.protection & kPDEFontNoEmbedding) == 0)
{
// Preview and print embedding OK, editing is NOT OK.
// Subset the embedded font.
fontCreateFlags = kPDEFontCreateEmbedded|kPDEFontWillSubset;
}
else
{
// Embedding not allowed.
fontCreateFlags = kPDEFontDoNotEmbed;
}

// trying not embedding; tmie to create legend is crazy
fontCreateFlags = kPDEFontDoNotEmbed;

// Create the PDE font. Embed if embedding information allows.
pdeFont = PDEFontCreateFromSysFont(sysFont, fontCreateFlags);

/* If font found, proceed */
if (pdeFont)
{

 

 

This topic has been closed for replies.

3 replies

Legend
December 14, 2022

You should be good to go on the font licensing (I wish I had fonts like that).

There isn't any specific way to enumerate only text.  Instead you'd just enumerate all the elements in the PDEContents for the page, and where the elements are text based, you have a PDEFont. Since you know the font name you can pick up a matching element (if any) and its PDEFont. Only if there isn't one after enumeration would you use PDEFontCreate.

At least that's my theory. In practice, I've found many things with PDFEdit don't work as you imagine they might.

Legend
December 14, 2022

PS. if the font might be on any page you will need to enumerate all of them. If there may be hundreds of pages it may be worth putting some hidden text in the font on page 1 to speed up the finding.

Known Participant
December 14, 2022

I just realized I left in  the change that disables it. It is idenitifed by a comment:

// trying not embedding; tmie to create legend is crazy
fontCreateFlags = kPDEFontDoNotEmbed;

 

which points out the other reason I don't want to embed at each teext run. This is in a function that is creating a legend showing characters that are used for tick marks in a document. They may be from any font, but I need to support use of a particular custome font that may not be on the system of everyone that needs to view the document. Generating the legen takes several minutes if embedding the font for each and only a few seconds if it uses the system's font without embedding.

Legend
December 14, 2022

I would check with the font vendor that your proposed use is permitted by the license that you purchased - effectively allowing a user to compose in a font they don't have a license for. Acrobat very specifically does not allow editing text in a font that is not installed locally, precisely because of the threat of legal action.  If it is allowed then, as I said, embed it only once (without subsetting), not each time it's used, by enumerating the existing text (which is the only way to pick up existing PDEFont objects).

Known Participant
December 14, 2022

It's a custom font developed for the client by a 3rd party, but the client owns it outright.  If they share the documentsthey review and mark up, they don't want tp have to provide the font.

Is there sample code that enumerates existing text to find PDEFonts?

Legend
December 14, 2022

There is no such thing as a document-level font. Fonts are associated with resources, on pages. They are often shared, but cannot be shared if they are subsets. My code adds fonts that may end up multiplying, but optimizes references in the same run to create only one PDEFont. PDFEdit does not give direct access to font resources though. I suggest enumerating existing text to see if there is an existing PDEFont for the same font (and attributes) and using that rather than creating a new font object.

Known Participant
December 14, 2022

Is there sample code that shares PDEFonts? Can it only be within that text run?