Aspose.Pdf - PDF merge - Exception

I am using Aspose.Pdf@24.7.0 to merge PDF files. My company has been using Aspose.Pdf for a long time for PDF processing. Recently, we upgraded to the latest version, but after the upgrade, the PDF merge process started causing problems. We encounter the following exceptions when trying to merge certain files using the façade method.

Code:

C#

string input1 = @"C:\test\Doc1.pdf";
string input2 = @"C:\test\Doc_Wrong.pdf";
string output = @"C:\test\Concatenate_Result_01.pdf";

PdfFileEditor pdfFileEditor = new PdfFileEditor
{
    KeepFieldsUnique = true,
    UniqueSuffix = "_%NUM%",
    CopyOutlines = false
};

var isSuccessful = pdfFileEditor.TryConcatenate(input1, input2, output);

Exception Details:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

Stack Trace:

Aspose.PDF.dll!Aspose.Pdf.Facades.PdfFileEditor.#=zuaJJhuY0eg6j(Aspose.Pdf.Document #=zPXbHrfw=, Aspose.Pdf.Document #=zQ$vHfWQ=, #=zR5pbxyW9r_ZhhH54lDFpacfW2c1Q #=zO6kansmqHKG_, #=zeO$64iJ1gpOCC0ISDWXy4F$mFCY1D$QQ0w==<string, Aspose.Pdf.Facades.PdfFileEditor.#=z7ir2YsHm7hrg> #=zcTuQmMpXmG9p) Unknown
Aspose.PDF.dll!Aspose.Pdf.Facades.PdfFileEditor.#=zwEzqkmuVGcHv(Aspose.Pdf.Document[] #=z7S2Nsqg=, ref Aspose.Pdf.Document #=zQ$vHfWQ=) Unknown
Aspose.PDF.dll!Aspose.Pdf.Facades.PdfFileEditor.Concatenate(string[] inputFiles, string outputFile) Unknown
Aspose.PDF.dll!Aspose.Pdf.Facades.PdfFileEditor.Concatenate(string firstInputFile, string secInputFile, string outputFile) Unknown
Aspose.PDF.dll!Aspose.Pdf.Facades.PdfFileEditor.#=zQjtPHkbsL5coHCdwaQ==.#=zh9LYbVq1jJVS7BxLuw==() Unknown
Aspose.PDF.dll!Aspose.Pdf.Facades.PdfFileEditor.#=zdz2aJbw=(System.Action #=zza3atnI=) Unknown
Aspose.PDF.dll!Aspose.Pdf.Facades.PdfFileEditor.TryConcatenate(string firstInputFile, string secInputFile, string outputFile) Unknown

Previously, we used Aspose.Pdf@21.9.0, and these files merged without any issues in that version. I would like to know what is causing the issue and if any code fixes are needed.

@riyasvk

It seems that you are encountering a System.NullReferenceException when trying to merge PDF files using the PdfFileEditor class in Aspose.Pdf version 24.7.0. This issue may arise due to several reasons, especially after an upgrade from an earlier version.

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

  1. Check Input Files: Ensure that both input PDF files (Doc1.pdf and Doc_Wrong.pdf) are valid and accessible. A NullReferenceException can occur if one of the files is not found or is corrupted.

  2. Update Code: Make sure that your code is correctly handling the file paths and that the PdfFileEditor object is properly instantiated. Here’s a simplified version of your code that you can use for testing:

    string input1 = @"C:\test\Doc1.pdf";
    string input2 = @"C:\test\Doc_Wrong.pdf";
    string output = @"C:\test\Concatenate_Result_01.pdf";
    
    PdfFileEditor pdfFileEditor = new PdfFileEditor();
    pdfFileEditor.KeepFieldsUnique = true;
    pdfFileEditor.UniqueSuffix = "_%NUM%";
    pdfFileEditor.CopyOutlines = false;
    
    try
    {
        var isSuccessful = pdfFileEditor.TryConcatenate(input1, input2, output);
        if (isSuccessful)
        {
            Console.WriteLine("PDF files merged successfully.");
        }
        else
        {
            Console.WriteLine("Failed to merge PDF files.");
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine($"An error occurred: {ex.Message}");
    }
    
  3. Review Release Notes: Check the release notes for version 24.7.0 to see if there are any breaking changes or known issues related to the PdfFileEditor class that might affect your implementation.

  4. Test with Different Files: Try merging different PDF files to determine if the issue is specific to the files you are currently using. This can help isolate whether the problem lies with the files or the code.

  5. Contact Support: If the issue persists after trying the above steps, consider reaching out to Aspose support with detailed information about the exception and the files you are using. They may provide insights specific to the version you are using.

By following these steps, you should be able to identify the cause of the exception and find a suitable solution.

Sources:

  • No specific sources were referenced in this response.

This is not a filepath issue. The TD occurs with PDFs that contain bookmarks and comments. Additionally, this worked fine in earlier versions of Aspose.Pdf.

@riyasvk
Could you please attach documents you mentioned in your code snippet so we can investigate this issue?

I can share the files mentioned in the code snippet for further investigation. Please find the attached documents.

Doc_Wrong.PDF (1.8 MB)

Doc1.pdf (49.8 KB)

1 Like

@riyasvk
Thanks, I’ll write you as soon as I check the issue

@riyasvk
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-58479

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.

@riyasvk
I tried to replicate your issue with 24.7 and latest version
I couldn’t reproduce it fully as I don’t get exception
However TryConcatenate fails for both version so I added task for this issue
Did I understand you correctly that issue isn’t present in that version?

as for exception - could you provide a bit more about version of framework and OS you are using?

Target Framework - .Net Framework 4.8

I am using the Aspose.PDF package for .NET Framework 4.0, version 24.7 (DLLs only). I have also tried the latest version of Aspose.PDF, but it has the same issue.

@riyasvk
Thanks, I’ll check with this framework

@riyasvk
I checked with mentioned framework, still the only issue I get is failed concatenation
Stack Trace gives error that “Aspose.Pdf.dll is unknown”, so I guess there could be some installation issues
Could you check if this issue is machine specific if it’s possible?