"Invalid font name" on document save after PDF -> PDF_A_2A conversion

Hello,

We’ve recently updated Aspose.PDF.Drawing to version 25.3.0 coming from 24.10.0 and have came across a PDF that cannot be saved after a successful conversion to PDF_A_2A.

This issue occurs on:

  • Both Aspose.PDF and Aspose.PDF.Drawing
  • Windows and Linux environment
  • 25.7.0 (latest to date)

Via trial and error we’ve found that version 25.1.0 is working for this scenario and a few versions before that - 23.8.0 at least. We are forced to downgrade.

Below you’ll find the exception stack trace as well as a code snippet.
Attached is a document that fails this
nullref_pdfa2a_redacted.pdf (2.9 KB)

The exception:

System.ArgumentException: Invalid font name
   at Aspose.Pdf.Text.FontCollection.get_Item(String name)
   at Aspose.Pdf.Text.FontCollection.#=z4Zp$g64=(String #=zhXAqv3UwLOzA)
   at #=zPbr5LX55Ajb7qggz_F0QvXhqPuOI.#=zWWuFWME=()
   at #=zLECicT7zjOcQNijllhKXxaJjhnl0.#=zWWuFWME=()
   at #=zpFS8iZY1VhDr5t20jfM$Ig4Rr8C0.#=zFV2k1tw=()
   at Aspose.Pdf.Document.#=zwvWfTbGfDZQB(PageCollection #=zohYuH0Q=)
   at Aspose.Pdf.Document.#=zV2lgdDKTMzjPPAIpNsaQfvs=(PageCollection #=zohYuH0Q=)
   at InvokeStub_Document.#=zV2lgdDKTMzjPPAIpNsaQfvs=(Object undefined, Span`1 undefined)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at dje_qMPBYFZXCBQ97FTJ3P4RQYL8KREKDXNHW7ECR533UZSDD96ECNPVA_ejd.#=z8NcHThWS8DfZW2ZACjtHILTdo6Ab(Object #=z4h4zHko=)
   at dje_qMPBYFZXCBQ97FTJ3P4RQYL8KREKDXNHW7ECR533UZSDD96ECNPVA_ejd.#=zH3OdpS3c1IlBSPcLPQrO13hkQ8kC(Object #=z4h4zHko=)
   at dje_qMPBYFZXCBQ97FTJ3P4RQYL8KREKDXNHW7ECR533UZSDD96ECNPVA_ejd.#=zbNC9638aqVJcptGQG2SpVIg=(MethodBase #=z4h4zHko=, Boolean #=z_a8GcYQ=)
   at dje_qMPBYFZXCBQ97FTJ3P4RQYL8KREKDXNHW7ECR533UZSDD96ECNPVA_ejd.#=zHPvwXL77WQip3xlSDmFT67$mZueiXUXx_Q==(dje_qMPBYFZXCBQ97FTJ3P4RQYL8KREKDXNHW7ECR533UZSDD96ECNPVA_ejd #=z4h4zHko=, #=q$iOIhR4YmJZTQU430x5H1grKMt7QXhAI0UzJUtCEHwY= #=z_a8GcYQ=)
   at dje_qMPBYFZXCBQ97FTJ3P4RQYL8KREKDXNHW7ECR533UZSDD96ECNPVA_ejd.#=z_XbvBb786mP77lXnP4mtNt8nZSva(Boolean #=z4h4zHko=)
   at dje_qMPBYFZXCBQ97FTJ3P4RQYL8KREKDXNHW7ECR533UZSDD96ECNPVA_ejd.#=z8NcHThWS8DfZW2ZACjtHILTdo6Ab(Object #=z4h4zHko=)
   at dje_qMPBYFZXCBQ97FTJ3P4RQYL8KREKDXNHW7ECR533UZSDD96ECNPVA_ejd.#=zH3OdpS3c1IlBSPcLPQrO13hkQ8kC(Object #=z4h4zHko=)
   at dje_qMPBYFZXCBQ97FTJ3P4RQYL8KREKDXNHW7ECR533UZSDD96ECNPVA_ejd.#=zrvMJ9DfBLRRhWVnTg2FVjCgL3SssB3nHgc_pjiM=(Object #=z4h4zHko=, UInt32 #=z_a8GcYQ=)
   at dje_qMPBYFZXCBQ97FTJ3P4RQYL8KREKDXNHW7ECR533UZSDD96ECNPVA_ejd.#=z_XbvBb786mP77lXnP4mtNt8nZSva(Boolean #=z4h4zHko=)
   at dje_qMPBYFZXCBQ97FTJ3P4RQYL8KREKDXNHW7ECR533UZSDD96ECNPVA_ejd.#=zxHjqePe44R1cu_Bcqn$EZZPXHf1m1kGLFaHXMJCgI8bO(Object[] #=z4h4zHko=, Type[] #=z_a8GcYQ=, Type[] #=zLJtWzOI=, Object[] #=zarldk$E=)
   at dje_qMPBYFZXCBQ97FTJ3P4RQYL8KREKDXNHW7ECR533UZSDD96ECNPVA_ejd.#=zPUvoyE76C68QA2dld6uGHM6NdLpB(Stream #=z4h4zHko=, String #=z_a8GcYQ=, Object[] #=zLJtWzOI=)
   at Aspose.Pdf.Document.#=ztiYSZqHFleW5(Stream #=z1vxfL2g=, SaveOptions #=zj6FyTUSUuos7)
   at Aspose.Pdf.Document.#=zfAgzTBXLWXgg(Stream #=z1vxfL2g=, SaveOptions #=zj6FyTUSUuos7)
   at Aspose.Pdf.Document.Save(Stream output)

The used code

private byte[] Convert(byte[] documentData)
{
    const PdfFormat format = PdfFormat.PDF_A_2A;
    using var stream = new MemoryStream(documentData);
    using var document = new Document(stream);
    using var reportStream = new MemoryStream();
    document.OptimizeResources(new() { UnembedFonts = false });
    document.EmbedStandardFonts = true;
    document.FontSubstitution += delegate (Font font, Font newFont)
    {
        Console.WriteLine($"FontSubstitution => font: {font?.FontName} newFont: {newFont?.FontName}");
    };
    var options = new PdfFormatConversionOptions(reportStream, format, ConvertErrorAction.Delete)
    {
        FontEmbeddingOptions =
        {
            UseDefaultSubstitution = true
        }
    };
    var conversionResult = document.Convert(options);
    if (!conversionResult)
    {
        var report = Encoding.ASCII.GetString(reportStream.ToArray());
        Console.WriteLine($"Conversion to {format} not possible. Conversion report: {report}");
        throw new ($"Error during pdf conversion to format {format}") { Data = { { "target", format } } };
    }
    document.Info.ModDate = DateTime.Now;
    using var output = new MemoryStream();
    document.Save(output); // THROWS HERE
    return output.ToArray();
}

@AdamD022

It sounds like you’re encountering an issue with the “Invalid font name” exception when saving a PDF after converting it to PDF/A-2A format. Since you’ve identified that the problem arises in versions 25.3.0 and later, but not in 25.1.0 or earlier, it appears to be a regression issue introduced in the newer versions.

Cause: The issue likely stems from changes in font handling in the newer versions, which may not be compatible with certain fonts used in your PDF.

Solution: Here are some steps you can take to troubleshoot and potentially resolve the issue:

  1. Font Embedding Options: Ensure that the font embedding options are correctly set. Try setting EmbedStandardFonts to false to see if that changes the behavior.

  2. Font Substitution: Since you’re using the FontSubstitution event, check the output of the Console.WriteLine to identify which fonts are being substituted. This may provide insight into the problematic font.

  3. Optimize Resources: You are currently optimizing resources with UnembedFonts set to false. Experiment with this setting to see if it affects the outcome.

  4. Check for Unsupported Fonts: Review the fonts used in the original PDF. If there are any non-standard or unsupported fonts, consider replacing them with standard fonts before conversion.

  5. Downgrade as a Temporary Solution: Since version 25.1.0 works, consider downgrading as a temporary solution while awaiting a fix in a future release.

  6. Contact Support: If the issue persists, reach out to Aspose support with the specific PDF file that causes the issue, along with the stack trace and your code snippet. They may provide a more targeted solution or a patch.

Next Steps: Implement the suggested troubleshooting steps and monitor the results. If the issue is resolved, great! If not, gather the necessary information and contact support for further assistance.

Let me know if these steps help or if you need further assistance!