Embedding Type 1 Fonts in Existing PDF

I am trying to embed fonts into an existing PDF with Aspose.PDF for .NET. I don’t seem to be able to embed any Type 1 fonts. I am setting the EmbedStandardFonts property to true at the document level. I am then looping through the page and form fonts using a code sample I found on your site, and setting IsEmbedded to true if the fonts and not already embedded. I have additionally set the FontOptions.NotifyAboutFontEmbeddingError to true, but am having no errors reported when I save the document. I have enclosed the code that attempts to embed the fonts below:

    public static int embedFonts(string dataDir)
    {
        if (!Directory.Exists(dataDir))
        {
            Console.WriteLine(string.Format("Input directory {0} does not exists", dataDir));
            return 1;
        }
        else
        {
            string[] pdfs = Directory.GetFiles(dataDir);
            foreach (string pdf in pdfs)
            {
                FileInfo fi = new FileInfo(pdf);
                if (fi.Extension.ToUpper().Equals(".PDF"))
                {
                    Document doc = new Document(pdf);
                    doc.EmbedStandardFonts = true;
                   

                    // Iterate through all the pages
                    foreach (Page page in doc.Pages)
                    {
                        if (page.Resources.Fonts != null)
                        {
                            foreach (Aspose.Pdf.Text.Font pageFont in page.Resources.Fonts)
                            {
                                // Check if font is already embedded
                                if (!pageFont.IsEmbedded)
                                {
                                    pageFont.FontOptions.NotifyAboutFontEmbeddingError = true;
                                    pageFont.IsEmbedded = true;
                                    //pageFont.IsSubset = true;
                                }
                                
                            }
                        }

                        // Check for the Form objects
                        foreach (XForm form in page.Resources.Forms)
                        {
                            if (form.Resources.Fonts != null)
                            {
                                foreach (Aspose.Pdf.Text.Font formFont in form.Resources.Fonts)
                                {
                                    // Check if the font is embedded
                                    if (!formFont.IsEmbedded)
                                    {
                                        formFont.FontOptions.NotifyAboutFontEmbeddingError = true;
                                        formFont.IsEmbedded = true;
                                        //formFont.IsSubset = true;
                                    }
                                    

                                }
                            }
                        }
                    }

                    String outputPDF = pdf + ".out";
                    try
                    {
                        doc.Save(outputPDF);
                    }
                    catch (FontEmbeddingException e)
                    {
                        Console.WriteLine("{0}", e.Message);
                    }
                    catch (FontNotFoundException e)
                    {
                        Console.WriteLine("{0}", e.Message);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("{0}", e.Message);
                    }
                }
            }
        }
        return 0;
    }

@cfinley

Thank you for contacting support.

Would you please share source and generated files so that we may try to reproduce and investigate it in our environment. Before sharing requested data, please ensure using Aspose.PDF for .NET 19.10.

I am using version 19.10. Attached file pdf-sample-in.pdf is the original with all the fonts un-embedded. File pdf-sample-out.pdf is the output from the above code (had to rename it from what the code indicates above because your system wouldn’t let me upload a “.out” file extension). All of the fonts with the exception of the Type 1 font get embedded into the output file. I have tried this same code on multiple pdfs with Type 1 fonts, and it never embeds them. I have pdfs with better type 1 font examples, but would not be allowed to upload them because they contain client/customer information.pdf-sample.pdf (7.8 KB)
pdf-sample-out.pdf (1.6 MB)

@cfinley

Please note that forum attachments are accessible to thread owner and Aspose staff only. Moreover, you can privately share the data as ZIP by clicking on my user name and then message icon so that we may proceed and assist you while considering better examples.

I believe the previously attached examples should be sufficient as they do provide an example of the problem. The only font that wasn’t embedded into the output PDF was the Type 1 font. I am seeing this behavior regardless of the PDF that I have tested thus far.

@cfinley

Thank you for sharing all the details.

We have been able to reproduce the issue in our environment. A ticket with ID PDFNET-47178 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.

Any resolution on this?

@ramachandra1988

We are afraid that the earlier logged ticket has not been yet resolved due to other issues in the queue logged prior to it. We have recorded your concerns under the ticket and will surely let you know as soon as we have some certain news about issue fix. Please spare us some time.

We are sorry for the inconvenience.