I will try to concatenate PDF files but have an error “Object reference not set to an instance of an object.” Error executed when call concatenate with any file + attached file.
More logs:
System.NullReferenceException: Object reference not set to an instance of an object.
at #=zt76wJhNQYphS2KPEmSFp6vmzqyPfgZ8Ah9DRmBQHGky8.#=zhA7OclYGT$dXZ3DIaQ==(Page #=z$tJfark=)
at #=zCjDsLxr38DvET_nunR5tuko8oxsmJAAHXz_Rnbk=.#=zmm7qa6otiCA9(Document #=zcEvbIbo=, Int32 #=zm5sozsU=, Document #=zSOD0mEg=)
at Aspose.Pdf.Facades.PdfFileEditor.#=z$hZ6xuDz_1hQ(Document[] #=z0RGtjUE=, Document& #=zYtsLn5U=)
at Aspose.Pdf.Facades.PdfFileEditor.Concatenate(String[] inputFiles, String outputFile)
My code:
PdfFileEditor pdfEditor = new PdfFileEditor
{
CopyLogicalStructure = parametersReader.CopyLogicalStructure(),
CloseConcatenatedStreams = true
};
var filesArray = files.Select(s => s.Path).ToArray();
pdfEditor.Concatenate(
filesArray,
tempFilePath);
I used ASPOSE 24.3.0 but try to update to 25.4.0 and problem still exist
File:
7. Bris material(837134) (0).pdf (4.6 MB)
@uaprogrammer
The error “Object reference not set to an instance of an object” typically indicates that there is a null reference in your code. This can happen for various reasons when concatenating PDF files. Here are some steps you can take to troubleshoot and resolve the issue:
-
Check Input Files: Ensure that all the PDF files you are trying to concatenate are valid and not corrupted. You can do this by opening each file individually to confirm they are accessible.
-
Use Corrupted File Handling: If you suspect that one or more of the PDF files might be corrupted, you can set the CorruptedFileAction
property of the PdfFileEditor
to handle corrupted files gracefully. For example:
pdfEditor.CorruptedFileAction = Aspose.Pdf.Facades.PdfFileEditor.ConcatenateCorruptedFileAction.ConcatenateIgnoringCorrupted;
-
Check File Paths: Make sure that the paths you are providing in the filesArray
are correct and that the files exist at those locations. You can log the paths to verify.
-
Update to Latest Version: Although you mentioned updating to version 25.4.0, ensure that you are using the latest version of the Aspose.PDF library, as newer versions may contain bug fixes and improvements.
-
Example Code: Here is a simple example of how to concatenate PDF files using the PdfFileEditor
:
PdfFileEditor pdfEditor = new PdfFileEditor();
pdfEditor.CorruptedFileAction = Aspose.Pdf.Facades.PdfFileEditor.ConcatenateCorruptedFileAction.ConcatenateIgnoringCorrupted;
string[] filesArray = { "path/to/first.pdf", "path/to/second.pdf" };
pdfEditor.Concatenate(filesArray, "path/to/output.pdf");
-
Debugging: If the issue persists, consider adding try-catch blocks around your code to catch exceptions and log more detailed error messages, which can help identify the exact cause of the null reference.
By following these steps, you should be able to identify and resolve the issue causing the null reference error during PDF concatenation. If you continue to experience problems, please provide additional details about the specific files you are using or any other relevant code snippets.
I already try this steps, but still have an error
@uaprogrammer
Thank you for writing to us.
I have reproduced the bug and will create a task for the development team.
@uaprogrammer
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-59725
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.