Convert PDF to PDFA - PDFA Convertion fails

Hi Support Team

We use the latest Aspose.pdf.dll with the version 25.1 with the following programcode and while converting we get various exceptions and dont know what to do and how to get further.
These documents are simple word documents that are saved as pdf. We want to convert these pdf’s to “PDF_A_2A” and get the mentioned error’s.

public static ConvertedResult ConvertDirectPathToPDFA(BaseDocument org_doc, AsposeSettings settings)
{
    var result = new ConvertedResult();
    try
    {
        var doc = new Document(org_doc.FullPath);
        doc.Convert($"{org_doc.OutPutPath}_report.xml", settings.PdfSaveSettings.PdfFormat, settings.PdfASaveSettings.ErrorAction);
        bool isValidated = doc.Validate(new MemoryStream(), settings.PdfSaveSettings.PdfFormat);
        var temp_doc = org_doc.OutPutPath + "\\" + org_doc.Name + ".pdf" ;
        doc.Save(temp_doc);

        var valid_Message = "";
        if (isValidated)
        {
            valid_Message = $" It is {settings.PdfSaveSettings.PdfFormat} valid.";
            RunConvert.pdfAValid++;
            result.Valid = true;
            
        }
        else
        {
            valid_Message = $" It is not valid.";
        }
        result.ConvertedDocument = GetMemoryStream(temp_doc).ToArray();
        result.Result = Result.Successful;
        result.Message = $"PDF Conversion was successful. {valid_Message}";
    }
    catch (Exception ex)
    {
        result.Result = Result.Error;
        result.Message = "ConvertToPDF was not successful";
        result.Valid = false;
        Logger.Error(ex);
        //throw ex;
    }
    finally
    {
        Logger.Debug("End of ConvertDirectPathToPDFA method.");
    }
    return result;

}

with the first document (1.pdf) we get the following error : {“The given key was not present in the dictionary.”}
1.pdf (314.0 KB)
1.pdf_error.jpg (261.5 KB)

with the second document (2.pdf) we get the following error: {“Object reference not set to an instance of an object.”}
2.pdf (5.3 MB)
2.pdf_error.jpg (285.7 KB)

What can we do with this error’s and how can we fix it?

we have a lot of documents found with this type of error’s and will inform you further of other kinds of error.

Thanks in advance for helping us to find a solution

@hasanirmak

It seems you are encountering exceptions while trying to convert PDF documents to PDF/A format using Aspose.PDF. The errors you mentioned, such as “The given key was not present in the dictionary” and “Object reference not set to an instance of an object,” can occur due to various reasons, including issues with the input PDF files or the conversion settings.

Here are some steps you can take to troubleshoot and potentially resolve these issues:

  1. Check Input PDF Files: Ensure that the PDF files you are trying to convert are not corrupted and are compliant with the PDF standards. You can try opening them in a PDF viewer to verify their integrity.

  2. Update Aspose.PDF Library: Make sure you are using the latest version of the Aspose.PDF library. Sometimes, bugs are fixed in newer releases, and updating might resolve your issue.

  3. Use Conversion Logs: When converting, you can generate a log file that details the conversion process. This can help identify what might be going wrong. In your code, you are already specifying a log file path in the Convert method. Check this log file for any specific errors or warnings that could provide more insight.

  4. Validation Before Conversion: Before attempting the conversion, validate the PDF document to ensure it meets the requirements for PDF/A compliance. You can use the Validate method to check the document’s compliance with the desired PDF/A standard.

  5. Error Handling: Enhance your error handling to capture more details about the exceptions. Instead of just logging the error, you might want to log the stack trace or any inner exceptions that could provide more context.

  6. Sample Code for Conversion: Here’s a simplified example of how to convert a PDF to PDF/A format, which you can compare with your implementation:

    using Aspose.Pdf;
    
    public static void ConvertToPDFA(string inputFilePath, string outputFilePath)
    {
        Document pdfDocument = new Document(inputFilePath);
        pdfDocument.Convert("conversion_log.xml", PdfFormat.PDF_A_2A, ConvertErrorAction.Delete);
        pdfDocument.Save(outputFilePath);
    }
    
  7. Consult Documentation: Review the Aspose documentation for any specific requirements or limitations regarding PDF/A conversion. This can provide insights into what might be causing the errors.

If the problem persists after trying these steps, consider reaching out to Aspose support with detailed information about the errors, the PDF files you are using, and the code you have implemented. This will help them assist you more effectively.

For further reading, you can check the following resources:

If you have any more questions or need further assistance, feel free to ask!

  • Check Input PDF Files: Files are not corrupted and ok. I have send you 2 example files (see 1.pdf and 2.pdf).

1.pdf (314.0 KB)
2.pdf (5.3 MB)

  • Update Aspose.PDF Library: i am using the latest version of the Aspose.PDF library 25.1.

  • Use Conversion Logs: When converting, i am generating a log file but the content is in both cases empty.
    xml report of 1.pdf and 2.pdf.jpg (70.8 KB)

  • Validation Before Conversion: i have also validated the pdf before converting and get still the same error while converting: {“The given key was not present in the dictionary.”} and {“Object reference not set to an instance of an object.”}

  var doc = new Document(org_doc.FullPath);
   bool isValidated = doc.Validate(new MemoryStream(), settings.PdfSaveSettings.PdfFormat);
   doc.Convert($"{org_doc.OutPutPath}_report.xml", PdfFormat.PDF_A_2A, ConvertErrorAction.Delete);// settings.PdfSaveSettings.PdfFormat, settings.PdfASaveSettings.ErrorAction);
  var temp_doc = org_doc.OutPutPath + "\\" + org_doc.Name + ".pdf" ;
  doc.Save(temp_doc);
  • Error Handling:
    for the file “1.pdf” i have the following detailed log:
2025-02-10 16:04:21,091 [1] [ERROR] in [Logic.AsposeToPDF] at [ConvertDirectPathToPDFA:63] - System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Collections.Generic.SortedDictionary`2.get_Item(TKey key)
   at #=zHOP4jYW663h2yJcSU1a$nd6ndY4Jm7ZRc5a0FywCncbfpAXABTMU3qf3BUxxCW0mRg==.#=zmcP6giPsrtKB4SxiUA==(#=z6sKYofmDB6xq0Pu9RFKhwltyE8WNejA1bVZQ86GVya9SOm8n3Q== #=zyHZ7nZ66w9zU, Dictionary`2 #=zF9bwZeJjVob0)
   at #=zHOP4jYW663h2yJcSU1a$nd6ndY4Jm7ZRc5a0FywCncbfpAXABTMU3qf3BUxxCW0mRg==.#=zaUUPCvlftWri()
   at #=zG_hZ0KFVOd$Vu0VgoDB6Il6eB7JJIw2J85_MdqlrfqfjdLpzv5z_$C0=.#=zxVHN0vweR9y5(#=znIyrmYK9qV1JPRJH26DwKvwtiNRu$MJZuEEbGyaWVgxUnUYXZg== #=zs3JmJ9Q=, #=zf1bKw0bATPBO_bsQ69Y1z_Hy5DCeuh6u_fXz97_epg_zVkFNSA== #=zzFPX55WQRxuZ)
   at #=zG_hZ0KFVOd$Vu0VgoDB6Il6eB7JJIw2J85_MdqlrfqfjdLpzv5z_$C0=.#=zgG6ojFg=()
   at #=zG_hZ0KFVOd$Vu0VgoDB6Il6eB7JJIw2J85_MdqlrfqfjdLpzv5z_$C0=.#=z6CafyS8=()
   at #=zgEtn9w7Ein38ugMGL6hgannB6dBsDOhkz1YC6C17gzKZxeLJEuyT7lA=.#=zGb7u3Rw=()
   at #=zG_hZ0KFVOd$Vu0VgoDB6Il6eB7JJIw2J85_MdqlrfqfjdLpzv5z_$C0=.#=zcpDqTq8=(XmlTextWriter #=znddg2oY=, PdfFormat #=zdbpOXPY=, Document #=zw62GAq4=, Boolean #=zxl5yfDZwUewC, ConvertErrorAction #=z9jCEnLI=)
   at Aspose.Pdf.Document.#=zzFxYPrY=(XmlTextWriter #=znddg2oY=, PdfFormat #=zdbpOXPY=, Boolean #=zxl5yfDZwUewC, ConvertErrorAction #=z9jCEnLI=, ConvertTransparencyAction #=z59UXlZ$45k7K4jHXjTOmKeM=)
   at Aspose.Pdf.Document.Convert(String outputLogFileName, PdfFormat format, ConvertErrorAction action, ConvertTransparencyAction transparencyAction)
   at Aspose.Pdf.Document.Convert(String outputLogFileName, PdfFormat format, ConvertErrorAction action)
   at ACPDF.Logic.AsposeToPDF.ConvertDirectPathToPDFA(BaseDocument org_doc, AsposeSettings settings) in C:\Users\labadmin\Development\Aspose\Aspose.Converter.PdfToPdfA\ACPDF\Logic\AsposeToPDF.cs:line 32
2025-02-10 16:04:27,890 [1] [INFO ] in [ACPDF.RunConvert] at [Main:95] - Error=> File Name: 1.pdf -Message: ConvertToPDF was not successful -Time: 9 seconds.

for the file “2.pdf” i have the following detailed log:

2025-02-10 16:04:30,138 [1] [ERROR] in [Logic.AsposeToPDF] at [ConvertDirectPathToPDFA:63] - System.NullReferenceException: Object reference not set to an instance of an object.
   at #=zG_hZ0KFVOd$Vu0VgoDB6Il6eB7JJIw2J85_MdqlrfqfjdLpzv5z_$C0=.#=zNWpu1K_K_PwV(Page #=zlKmJpsA=, OperatorCollection #=zYNs5CcE=, Resources #=z9URQ63o=, Int32 #=zjZTbOT8JHlbl, #=zf1bKw0bATPBO_bsQ69Y1z_Hy5DCeuh6u_fXz97_epg_zVkFNSA== #=zzFPX55WQRxuZ)
   at #=zG_hZ0KFVOd$Vu0VgoDB6Il6eB7JJIw2J85_MdqlrfqfjdLpzv5z_$C0=.#=zJgsi88c_GMWu(Page #=zlKmJpsA=, #=zf1bKw0bATPBO_bsQ69Y1z_Hy5DCeuh6u_fXz97_epg_zVkFNSA== #=zzFPX55WQRxuZ)
   at #=zG_hZ0KFVOd$Vu0VgoDB6Il6eB7JJIw2J85_MdqlrfqfjdLpzv5z_$C0=.#=zgG6ojFg=()
   at #=zG_hZ0KFVOd$Vu0VgoDB6Il6eB7JJIw2J85_MdqlrfqfjdLpzv5z_$C0=.#=z6CafyS8=()
   at #=zgEtn9w7Ein38ugMGL6hgannB6dBsDOhkz1YC6C17gzKZxeLJEuyT7lA=.#=zGb7u3Rw=()
   at #=zG_hZ0KFVOd$Vu0VgoDB6Il6eB7JJIw2J85_MdqlrfqfjdLpzv5z_$C0=.#=zcpDqTq8=(XmlTextWriter #=znddg2oY=, PdfFormat #=zdbpOXPY=, Document #=zw62GAq4=, Boolean #=zxl5yfDZwUewC, ConvertErrorAction #=z9jCEnLI=)
   at Aspose.Pdf.Document.#=zzFxYPrY=(XmlTextWriter #=znddg2oY=, PdfFormat #=zdbpOXPY=, Boolean #=zxl5yfDZwUewC, ConvertErrorAction #=z9jCEnLI=)
   at Aspose.Pdf.Document.Validate(Stream outputLogStream, PdfFormat format)
   at ACPDF.Logic.AsposeToPDF.ConvertDirectPathToPDFA(BaseDocument org_doc, AsposeSettings settings) in C:\Users\labadmin\Development\Aspose\Aspose.Converter.PdfToPdfA\ACPDF\Logic\AsposeToPDF.cs:line 31
2025-02-10 16:04:30,140 [1] [INFO ] in [ACPDF.RunConvert] at [Main:95] - Error=> File Name: 2.pdf -Message: ConvertToPDF was not successful -Time: 1 seconds.
  • Sample Code for Conversion: i use the same code as you mentioned and still getting error.
    Consult Documentation: i have read the documentation and there is nothing special about these pdf’s or the method.

thanks in advance for anay help

@hasanirmak

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-59273

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.