Copy link to clipboard
Copied
Hi,
I Want to convert non embedded font to embedded font using Acrobat SDK.
I am using below code to do that. It was creating new font and it was not updating existing font.
PDDoc pdDoc = AVDocGetPDDoc(AVAppGetActiveDoc());
CosObj fontObj = PDFontGetCosObj(font);
PDEFont pdeFont = PDEFontCreateFromCosObj(&fontObj);
PDEFontAttrs attrs;
memset(&attrs, 0, sizeof(attrs));
PDEFontGetAttrs(pdeFont, &attrs, sizeof(attrs));
PDSysEncoding sysEnc = NULL;
if (attrs.type == ASAtomFromString("Type0"))
{
sysEnc = PDSysEncodingCreateFromCMapName(attrs.encoding);
}
else
{
//Collect the /Differences from the /BaseEncoding if present for a simple font.
//std::vector<const char*> differencesEncoding = CollectEncodingDifferencesIfPresent(fontEntry->fontCosObj);
//sysEnc = PDSysEncodingCreateFromBaseName(attrs.encoding, differencesEncoding.size() > 0 ? &(*differencesEncoding.begin()) : NULL);
}
PDSysFont pdSysFont = PDFindSysFontForPDEFont(pdeFont, kPDSysFontMatchNameAndCharSet);
// If the font is not found on the system, sysFont will be 0.
if (0 == pdSysFont)
{
//std::cout << "Could not find a pdSysFont " << std::endl;
return;
}
PDEFontSetSysFont(pdeFont, pdSysFont);
if (sysEnc)
PDEFontSetSysEncoding(pdeFont, sysEnc);
if (attrs.cantEmbed != 0)
{
//std::cout << "Font " << ASAtomGetString(attrs.name) << " cannot be embedded" << std::endl;
}
else
{
if (PDEFontIsMultiByte(pdeFont))
{
// Subset embed font
PDEFont pdeFont;
if (sysEnc)
pdeFont = PDEFontCreateFromSysFontAndEncoding(pdSysFont, sysEnc, attrs.name, kPDEFontCreateEmbedded | kPDEFontCreateSubset);
else
pdeFont = PDEFontCreateFromSysFont(pdSysFont, kPDEFontCreateEmbedded | kPDEFontCreateSubset);
PDEFontSubsetNow(pdeFont, PDDocGetCosDoc(pdDoc));
PDERelease((PDEObject)pdeFont);
}
else
{
// Fully embed font
PDEFont pdeFont = PDEFontCreateFromSysFont(pdSysFont, kPDEFontCreateEmbedded);
PDEFontEmbedNow(pdeFont, PDDocGetCosDoc(pdDoc));
PDERelease((PDEObject)pdeFont);
}
}
if (sysEnc)
PDERelease((PDEObject)sysEnc);
Please help me to solve this issue.
Copy link to clipboard
Copied
You make a PDEFont but do nothing with it. Surely, you need to use PDFEdit on the existing text? You cannot assume that, even if you were to embed new text with the same font, embedded, that the OTHER text will magically use the embedded font.
Copy link to clipboard
Copied
Consider too: for some fonts you have just created the font, then you say "PDEFontSubsetNow". Consider that a font subset is designed to contain the characters used in a font. But you have not used any characters! Are you asking it to embed an empty font. I think you are seeing a font as a property of the entire PDF - there is one font with a name, it's embedded or not. But that isn't the case. Each text block COULD have a different font object, possibly naming the same font with a different subset (or multiple full fonts). Acrobat will sometimes (at undocumented times) consolidate multiple font objects into one, but you can't rely on this happening. (I worked with PDEFonts some years ago and I did indeed find it difficult and confusing, and I'm pretty sure I found some Acrobat bugs too).
Copy link to clipboard
Copied
Hi,
I want to embed specific font in the page.
for example there one text present in page 3 which has font "Helvetica" and this font is not embedded.
My requirement is it should be embed. I have go throgh te Acrobat SDk document and i used below function to do this.
But it was not working as expected.
PDEFont pdeFont = NULL;
PDEFontAttrs pdeFontAttrs;
PDSysFont sysFont;
ASUns32 fontCreateFlags;
memset(&pdeFontAttrs, 0, sizeof(pdeFontAttrs));
// Find the matching system font.
pdeFontAttrs.name = ASAtomFromString("Helvetica");
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 policy for Preview & Print, or editing.
// Based on the font permission policy, decide whether to embed/subset
// the font.
if ((pdeFontAttrs.protection & kPDEFontNoEditableEmbedding) == 0) {
// Editing OK. Embed the entire font.
fontCreateFlags = kPDEFontCreateEmbedded;
}
else if ((pdeFontAttrs.protection & kPDEFontNoEmbedding) == 0) {
// Preview & Print embedding OK, editing is NOT OK.
// Subset the embedded font.
fontCreateFlags = kPDEFontCreateEmbedded | kPDEFontWillSubset;
}
else {
// Embedding not allowed.
fontCreateFlags = kPDEFontDoNotEmbed;
}
// Create the PDE font. Embed if embedding information allows.
pdeFont = PDEFontCreateFromSysFont(sysFont, fontCreateFlags);
PDEFontEmbedNow(pdeFont, PDDocGetCosDoc(AVDocGetPDDoc(AVAppGetActiveDoc())));
//PDEFontSubsetNow
PDERelease((PDEObject)pdeFont);
Please let me know if i missed anything in the code and any other solution to do this.
Thanks
Copy link to clipboard
Copied
I already replied in detail the same day. Why did you just repost your question after 2 weeks without changing your code?? Looks like I wasted my time replying, explaining, and giving a direction to follow; I won't make that mistake again.
Copy link to clipboard
Copied
Sorry for posting same question but the code what i have posted is recently i investigating in the Adobe then i got and used same code to solve my issue. but it was not working as expected. So Actually i have added this code in the post.
I have referring this code in the below link.
https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/FontPolicies.pdf
Thanks,
Copy link to clipboard
Copied
Hello,
I have done some investigation to make embed the font present in the pdf document. But i could not able to achieve this.
Please help me how to convert non embedded font to embedded font in the PDF document.
I am using PDEFontEmbedNow API cal to embed the font.
Using this API can we achive this or any other APIs do i need to go through.
Thanks
Copy link to clipboard
Copied
I responded promply to your original request with a detailed review of what you were failing to do. I will certainly not let you waste any more of my time.
Copy link to clipboard
Copied
You are, by the way, the most rude person I have dealt with in these forums for several years. To ignore a detailed reply once is rude enough, but to keep posting as if the original reply did not exist is intolerable. If your boss asks you why this is taking so long, you may tell him you need a course in basic etiquette.