Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Jul 24, 2017 3:11 pm

Hi,
I am getting System.OutOfMemoryException when trying to merge multiple pdfs with Spire.pdf. I am using latest build (Spire.PDF Pack(Hot Fix) Version:3.9.82).
I have tried two approaches (1) with AppendPage and (2) with MergeFiles. In both cases I am getting same exception. I have calculates that all files could sum up to the size of 230 MP approax.

Given below is the code I am using, Please help me.

Code: Select all
foreach (var file in files)
                {
                    var filePath = string.Format("{0}{1}.pdf", targetLocationPath, file);

                    if (File.Exists(filePath))
                    {
                        mainPdfDocument.AppendPage(new PdfDocument(filePath));

                    }
                }

                mainPdfDocument.SaveToFile(mainFileStringPath, Spire.Pdf.FileFormat.PDF);


and
Code: Select all
var newPdf = PdfDocument.MergeFiles(files.Select(s => string.Format("{0}{1}.pdf", targetLocationPath, s)).ToArray());
newPdf.Save(mainFileStringPath);

vktewthia
 
Posts: 1
Joined: Thu Mar 02, 2017 8:16 am

Tue Jul 25, 2017 1:37 am

Dear vktewthia,

Thanks for your inquiry.
Now the latest version is Spire.PDF Pack(Hot Fix) Version:3.9.226, we suggest upgrading to this version to check if the issue is solved. If it still happens, due to the memory usage is completely dependent on document size and document complexity, please offer us the input files here or send it to us(support@e-iceblue.com) via email for investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Nov 06, 2019 2:32 pm

I am getting the same problem. I am using the latest service pack.
I have simplified my code to be as basic as possible (straight from your examples)
I get System.OutOfMemoryException: 'Exception of type 'System.OutOfMemoryException' was thrown.' on line 3
Doc2 is 22MB (it will not let me upload it as an attachment)
Any help would be appreciated

Code: Select all
Dim files As String() = New String() {"C:\Users\martinb.ADBMS\AppData\Local\Temp\PPTemp\Doc1.pdf", "C:\Users\martinb.ADBMS\AppData\Local\Temp\PPTemp\Doc2.pdf"}
Dim outputFile As String = "result.pdf"
Dim doc1 As PdfDocumentBase = PdfDocument.MergeFiles(files)
doc1.Save(outputFile, FileFormat.PDF)

martinb13
 
Posts: 4
Joined: Sun Feb 02, 2014 11:08 am

Thu Nov 07, 2019 3:16 am

Hi,

Thanks for your inquiry.
Do you use the latest Spire.PDF Pack(Hot Fix) Version:5.11.0? After testing, I didn't reproduce your issue, the merged PDF could be generated successfully.

If you still have the issue, please provide the OS and Region(e.g. Win7 64bit, RAM:8GB, China/Chinese) information for further investigation.

Best wishes,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF