Convert PDF to PDF/A | Aspose.PDF for .NET | Font Names transformation

Hello,
I am using Aspose.Pdf to convert PDF files to the PDF/A standard. In the process, I noted that when converting a PDF file with some embedded fonts (Sample_input.pdf) the processed file has other font names (some kind of parsing that strips dashes) and it can’t be opened because the text styles now reference a font, which is no longer embedded (Sample_output.pdf).

sample-output.pdf (141,2 KB)
sample-input.pdf (195,2 KB)

Code used (C#):

using (var doc = new Document(input))
{
    var options = new PdfFormatConversionOptions(errorStream, PdfFormat.PDF_A_3B, ConvertErrorAction.None)
    {
        OptimizeFileSize = true,
        ExcludeFontsStrategy = RemoveFontsStrategy.SubsetFonts | RemoveFontsStrategy.RemoveDuplicatedFonts
    };
    doc.Convert(options);
    doc.Save(output);
}

The font files in the original pdf are named like Stratos-Bold, Stratos-Regular, etc. But in the output they are renamed to StratosBold, StratosRegular, etc. and are not properly embedded.

@daniel.castilla

When converting PDF files to the PDF/A standard using Aspose.PDF for .NET, it’s important to ensure that all fonts are properly embedded to avoid issues with font names and document accessibility. The problem you’re encountering, where font names are altered (e.g., from “Stratos-Bold” to “StratosBold”) and fonts are not embedded, can lead to the output PDF being unopenable.

To address this issue, you can use the font substitution feature provided by Aspose.PDF. This allows you to replace missing fonts with alternative fonts that are available on your system. Here’s how you can implement this in your code:

  1. Load the PDF Document: Start by loading your input PDF document.
  2. Set Up Font Substitution: Use the SimpleFontSubstitution class to specify which fonts to substitute if they are missing.
  3. Convert the Document: Convert the document to the desired PDF/A format while ensuring that the fonts are embedded.

Here’s an example code snippet that demonstrates how to implement font substitution during the conversion process:

using System;
using System.IO;
using Aspose.Pdf;
using Aspose.Pdf.Text;

class Program
{
    static void Main()
    {
        string input = "path/to/sample_input.pdf";
        string output = "path/to/sample_output.pdf";

        // Load the PDF document
        using (var doc = new Document(input))
        {
            // Set up font substitution
            FontRepository.Substitutions.Add(new SimpleFontSubstitution("Stratos-Bold", "Arial"));
            FontRepository.Substitutions.Add(new SimpleFontSubstitution("Stratos-Regular", "Arial"));

            // Convert to PDF/A-3B
            var options = new PdfFormatConversionOptions("errorLog.xml", PdfFormat.PDF_A_3B, ConvertErrorAction.Delete)
            {
                OptimizeFileSize = true
            };
            doc.Convert(options);
            doc.Save(output);
        }
    }
}

In this example, replace "Arial" with any other font that you want to use as a substitute. This approach ensures that the fonts are embedded correctly in the output PDF/A file, maintaining the document’s integrity and accessibility.

For more detailed guidance on converting PDFs to PDF/A formats and handling font embedding, you can refer to the official Aspose documentation on PDF/A conversion and font management here and here.

If you continue to experience issues, please ensure that the fonts you are substituting are available on your system and that you are using the latest version of the Aspose.PDF library.

Sources:
[1]: Convert PDF to PDF/A formats|Aspose.PDF for .NET - Aspose Documentation
[2]: Replace Missing Fonts | Aspose.PDF for .NET API Reference

Please, be aware, that the fonts in my sample input are correctly embedded.

@daniel.castilla

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-59854

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.