Concatenating PDFs generated by Aspose.PDF fail with NullReferenceException

Concatenation fails when merging PDFs generated by Aspose.PDF .NET (11.5 for .net3.5). I'm able to concatenate non-Aspose created PDFs without issue.

I'm using the latest version of Aspose.PDF and Aspose.Word (16.3 for .net2.0). I'm running Windows8.1 Pro x64 with latest updates installed. I created a .NET 3.5 console application that generates two Aspose.Word.Document using a memory stream and then saves them to PDF. I confirm the PDF files generated are viewable and then concatenate them, but this error is thrown:

PDFIsValid = True
PDFIsValid = True
System.NullReferenceException: Object reference not set to an instance of an object.
at Aspose.Pdf.Facades.PdfFileEditor.☻(Exception ☻)
at Aspose.Pdf.Facades.PdfFileEditor.Concatenate(String[] inputFiles, String outputFile)
at AsposeConcatenate.Program.Main(String[] args) in c:\Development\TrustOnline\TrustOnline\Utility\AsposeConcatenate\
AsposeConcatenate\Program.cs:line 59
No corrupted documents.

/////////////////////
using System;
using System.IO;
using Aspose.Pdf.Facades;

namespace AsposeConcatenate
{
class Program
{
static void Main(string[] args)
{
if (File.Exists("output.pdf")) File.Delete("output.pdf");
if (File.Exists("template.pdf")) File.Delete("template.pdf");
if (File.Exists("template2.pdf")) File.Delete("template2.pdf");

{
var license = new Aspose.Pdf.License();
license.SetLicense("Aspose.Total.lic");
}
{
var license = new Aspose.Words.License();
license.SetLicense("Aspose.Total.lic");
}

using (var memoryStream = new MemoryStream())
using (var writer = new StreamWriter(memoryStream))
{
writer.Write("some text");
writer.Flush();

var newDoc = new Aspose.Words.Document(memoryStream);
try
{
newDoc.Save("template.pdf", Aspose.Words.SaveFormat.Pdf);
newDoc.Save("template2.pdf", Aspose.Words.SaveFormat.Pdf);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return;
}
}

string[] filesArray = new string[2];
filesArray[0] = "template.pdf";
filesArray[1] = "template2.pdf";
// Confirm files are valid
foreach (string file in filesArray)
{
Console.WriteLine("PDFIsValid = {0}", PdfIsValid(file));
}

PdfFileEditor pdfEditor = new PdfFileEditor();
pdfEditor.CorruptedFileAction = PdfFileEditor.ConcatenateCorruptedFileAction.StopWithError;
pdfEditor.CloseConcatenatedStreams = true;
pdfEditor.AllowConcatenateExceptions = true;
try
{
bool result = pdfEditor.Concatenate(filesArray, "output.pdf");
Console.WriteLine("Concatenate Result = {0}", result);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}

if (pdfEditor.CorruptedItems.Length > 0)
{
Console.WriteLine("Corrupted documents:");
foreach (PdfFileEditor.CorruptedItem item in pdfEditor.CorruptedItems)
{
Console.WriteLine(item.Index + " reason " + item.Exception.Message);
}
}
else
{
Console.WriteLine("No corrupted documents.");
}

Console.ReadLine();
}

public static bool PdfIsValid(string fileName)
{
try
{
var doc = new Aspose.Pdf.Document(fileName);
}
catch (Exception e)
{
Console.WriteLine(e);
return false;
}
return true;
}
}
}


Hi Matt,


Thanks for using our API’s.

I have tested the scenario and have managed to reproduce same problem. For the sake of correction, I have logged it as PDFNEWNET-40658 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Any update on this issue?

Hi Matt,


Thanks for your inquiry. It seems your issue has been fixed in Aspose.Pdf for .NET 11.6.0 in result of some other fix. Please download and try latest version of Aspose.Pdf for .NET, it will resolve the issue.

Please feel free to contact us for any further assistance.

Best Regards,