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


8 Replies

MR MrHessellund October 3, 2021 08:08 AM UTC

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;
        }







SV Surya Venkatesan Syncfusion Team October 4, 2021 02:50 PM UTC

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



MR MrHessellund October 5, 2021 08:10 AM UTC

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,




SV Surya Venkatesan Syncfusion Team October 6, 2021 11:18 AM UTC

Hi MrHessellund, 
 
Thank you for your update. 

On further analysis, we request you to confirm whether you need to ensure the PDF document contains all fonts are embedded or not? If this requirement is sufficient, we will plan to provide the IsAllFontEmbed bool property in the PdfLoadedDocument class, that will helpful to ensure whether the given document contains all font is embedded or not.  

Otherwise if you want to find the non-embedded fonts in the PDF document and then you want to update that font means the above planned requirement is not effective. So, Kindly share your complete requirements of ensuring the all embedded fonts. That will be helpful for us to provide the efficient solution as earlier as possible. 

Regards, 
Surya V 



MR MrHessellund replied to Surya Venkatesan October 7, 2021 10:48 AM UTC

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



SV Surya Venkatesan Syncfusion Team October 8, 2021 11:11 AM UTC

Hi Johannes Hessellund, 
  
Thank you for your update. 
 
As we already mentioned, we will have planned to provide the IsAllFontEmbed bool property in the PdfLoadedDocument class. In addition, we found based on your code to embed the non-embeded fonts to the PDF document as like PdfLoadedDocument.EmbedFont(font). Currently we are analyzing this requirement on our end and update you the further details on October 11th 2021. 
 
Regards, 
Surya V 



SV Surya Venkatesan Syncfusion Team October 11, 2021 12:21 PM UTC

Hi Johannes Hessellund, 
  
Thank you for your patience.

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.
 
Please use the below feedback link to track the status of this feature. 
 
Please refer the below code snippet, 
           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"); 
 
 
Note: Public API name subject to change. 
 
Note: If you require patch for the reported support in any of our Essential Studio Main or SP release version, then kindly let us know the version, so that we can provide a patch in that version based on our SLA policy. 

Please let us know if you have any concern on this.
 
 
Regards, 
Surya V 



GK Gowthamraj Kumar Syncfusion Team October 25, 2021 02:49 PM UTC

Hi Johannes, 

Thank you for your patience.

 
We have implemented the feature with Support to embedding the non-embedded font in existing pdf document in latest version 19.3.0.43 .The patch for this support can be downloaded from the following location.     
 
Recommended approach - exe will perform automatic configuration     
Please find the patch setup from below      
   
Advanced approach – use only if you have specific needs and can directly replace existing assemblies for your build environment     
Please find the patch assemblies alone from below      
 
  
   
Please use the below feedback link to track the status of this feature.   
   
Please refer the below code snippet,  
              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");  
     
 Note: Public API name subject to change.  
 
Assembly Version: 19.3.0.43   
   
Installation Directions : 
 
This patch should replace the files “Syncfusion.Pdf.Base.dll” under the following folder.    
$system drive:\ Files\Syncfusion\Essential Studio\$Version # \precompiledassemblies\$Version#\4.6    
Eg : $system drive:\Program Files\Syncfusion\Essential Studio\9.3.0.61\precompiledassemblies\9.3.0.61\4.0    

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   
 
    
Disclaimer :
We will include this support in our 2021 Volume 3 SP1 release which will be available on end of November 2021 tentatively.   
 
 
Regards, 
Gowthamraj K

Loader.
Up arrow icon