We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Out of memory exception during concatenation

Hi, I am trying to concatenate 100 1 page documents together but I am recieving an out of memory exception. I found a different way around it but getting the pages of each document and adding them to the pages collection of a new pdf I created but it is pretty slow. Is there another way around the out of memory exception?


Hi John,

Thanks for your interest in our products.

Can you please share some details regarding the template PDF documents and code snippet you are using. This will help us to figure out the issue and reply back to you soon.

We apologize for your inconvenience.

Thanks & Regards,

I looked into it a little more deeply and found out that the test I wrote was using a 1 page pdf that included a high res photo on the first page. When using the following code to concatenate the pdf 100 times it would through an out of memory exception once the process consumed right around 1500mb. Below is the method that I am using to concatenate them together, and when the Concatenate is called the LastException property will hold the value of “Exception of type ‘System.OutOfMemoryException’ was thrown.”


public void Stitch(string outputFile, params string[] inputDocumentPaths)
{
var editor = new PdfFileEditor();
editor.CloseConcatenatedStreams = true;
var result = editor.Concatenate(inputDocumentPaths, outputFile);

if (!result)
{
throw new ApplicationException(editor.LastException.Message, editor.LastException.InnerException);
}
}

If I use another pdf that has 18 pages of only text and grey scale images the Concatenate function works fine but can be very very slow. Below is the way I got around the problem of the Out of Memory exception by opening and taking all the pages of each document and adding them to the target pages collection. This method works fine for all pdf files except for pdf files that include 3D images which we need to support, so this method will not work for us. The method below is also even slower then using the Concatenate method as I am opening and closing the documents over and over again, but it does get the job done, just very slowly.

public void Stitch(string outputFile, params string[] inputDocumentPaths)
{
Pdf pdf = new Pdf();
pdf.Save(outputFile);</b>
var outputStream = new FileStream(outputFile, FileMode.OpenOrCreate);

foreach (var documentPath in inputDocumentPaths)
{
var outputDocument = new Document(outputStream);
var document = new Document(documentPath);
outputDocument.Pages.Add(document.Pages);
document.Dispose();
outputDocument.Save();
}
outputStream.Close();
}

Attached I have included the pdf files that I am trying to use.

Hi John,

I apologize for the delay in the response.

I have tested the scenerio and able to notice the same problem when concatinating PDF document 100 times, however this is working when we trying to concate the PDF document 85 times, in this case, the resultant PDF size is 1.27 GB. The problem may occur due to large file size and rendering time is slow because PDF document has high resolution image.

I am afraid 3D PDF document feature is not supported at the moment. We will investigate, if we can support the feature in our future version.

We apologize for your inconvenience.

Thanks & Regards,