How can we ensure all fonts or subset are embedded
Hi,
In Germany it is becoming a requirement that all fonts are embedded in the PDF before submission in legal matters.
How can we ensure that all fonts are embedded in the PDF? Using .NET Framework version.
Of course here I also think of fonts not availble on the current system.
Please advise
The below snippet seems to somewhat work, but is very inefficient, especially on large documents. Please advise of better
public static bool EmbedUsedFonts(PdfLoadedDocument ldoc)
{
try
{
if (ldoc.UsedFonts == null || ldoc.UsedFonts.Length == 0)
{
return false;
}
for (int i = 0; i < ldoc.UsedFonts.Count(); i++)
{
if (!ldoc.UsedFonts[i].Type.ToString().Contains("Embed"))
{
try
{
ldoc.UsedFonts[i].Replace(
new PdfTrueTypeFont(
new Font(ldoc.UsedFonts[i].Name, ldoc.UsedFonts[i].Size),
GetFontStyle(ldoc.UsedFonts[i].Style),
ldoc.UsedFonts[i].Size,
false, true)
);
}
catch (Exception e)
{
// Font not available?
Console.WriteLine(string.Format("Font: {0} not available"), ldoc.UsedFonts[i].Name);
}
}
}
return true;
}
catch (Exception e)
{
return false;
}
return false;
}
Hi MrHessellund,
We can only identify the embedded font by using Type property from the PdfUsedFont in an existing PDF document. In this API, we can retrieve all fonts from the existing PDF document.
Please find the code snippet below,
|
loadedDocument.UsedFonts[i].Type |
Using this approach, we can find the existing font is embed or not.
Regards,
Surya V
Hi,
But then how to I ensure that non-embedded font get embedded?
During your conversion to PDF/A format, it shall also be ensured that all fonts are embedded or at least substitution fonts are embedded. How can this be done without conversion to PDF/A ?
Best regards,
Hi,
The IsAllFontsEmbedded bool property would be helpful.
However, we need some efficient way to embed all fonts which are not embedded.
Thus, something like this would be good:
if (PdfLoadedDocument.IsAllFontsEmbedded == false)
{
for each (Font font in PdfLoadedDocument.UsedFonts)
{
if (font.IsEmbedded == false)
{
PdfLoadedDocument.EmbedFont(font);
}
}
}
Best rega
On our further analysis, we have consider this requirement as usability feature with “Support to embedding the non-embedded font in existing pdf document” and we will update the patch for this support on October 25th, 2021.
|
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"../../Data/input.pdf");
var fonts = loadedDocument.UsedFonts;
if (loadedDocument.IsAllFontsEmbedded == false)
{
foreach(PdfUsedFont font in fonts)
{
if (font.Type != PdfFontType.TrueTypeEmbedded)
{
loadedDocument.EmbedFont(font);
}
}
}
loadedDocument.Save("Output.pdf"); |
Please let us know if you have any concern on this.
|
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"../../Data/input.pdf");
var fonts = loadedDocument.UsedFonts;
if (loadedDocument.IsAllFontsEmbedded == false)
{
foreach(PdfUsedFont font in fonts)
{
if (font.Type != PdfFontType.TrueTypeEmbedded)
{
loadedDocument.EmbedFont(font);
}
}
}
loadedDocument.Save("Output.pdf"); |
To automatically run the Assembly Manager, please check the Run assembly manager checkbox option while installing the patch. If this option is unchecked, the patch will replace the assemblies in precompiled assemblies’ folder only. Then, you will have to manually copy and paste them to the preferred location or you will have to run the Syncfusion Assembly Manager application (available from the Syncfusion Dashboard, installed as a shortcut in the Application menu) to re-install assemblies.
Note :
To change how you receive bug fixes, ask your license management portal admin to change your project’s patch delivery mode.
https://www.syncfusion.com/account/license
We will include this support in our 2021 Volume 3 SP1 release which will be available on end of November 2021 tentatively.
- 8 Replies
- 3 Participants
-
MR MrHessellund
- Oct 3, 2021 06:14 AM UTC
- Oct 25, 2021 02:49 PM UTC