Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Sep 08, 2021 7:08 am

Hello!
I need to join six o seven pdfs of 500Megas each one of them.
The first step is to make a new PdfDocument of each of them. This is not possible as with such large files I get a 'System.OutOfMemoryException' error.
If I divide them and then apply the MergePdf using divided PDFs, I am in the same ones because the error finally gives me the MergePDF operation.
That is, I delay the error but I can't join my PDFs.

What is the solution? What are the limits of the functions that we have discussed?

Thank you very much for your help!

LauraNM
 
Posts: 77
Joined: Tue Feb 19, 2019 1:23 pm

Wed Sep 08, 2021 10:00 am

Hello,

Thanks for your inquiry.
Regarding loading and merging large PDFs, please kindly note that this does need a lot of memory space. As the 32-bit project memory is limited to 2GB, if your project is 32-bit, please try to change the platform target of the project to 64-bit (as shown in the screenshot) in Visual Studio before testing. Hope it can help you.
In addition, if you are not using the latest version, I suggest you download and use the latest Spire.Office v6.8.2 for testing. If the issue still exists after testing, in order to help us further investigate it, please provide some of your input documents and full test code. Thanks in advance.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Wed Sep 08, 2021 11:27 am

Hello!
my system is 64 bit.
And it does not depend on the files but on their initial size.
Is it possible to compress the files before doing the Merge?
what I get when doing the merge is a PdfDocumentBase.
Can you convert this PdfDocumentBase resulting from the merge, into a PdfDocument, and compress it before saving?

Thank you very much for your help!

LauraNM
 
Posts: 77
Joined: Tue Feb 19, 2019 1:23 pm

Wed Sep 08, 2021 12:15 pm

Hello!

I have tried to use these two functions that I have seen in the forum but the first one does not compress anything and the second one always returns an error of: Out of memory.
Is there any other way to compress a pdf using Spire?

Thank you very much for your help!

public void CompressContent(PdfDocument doc)
{
//Disable the incremental update
doc.FileInfo.IncrementalUpdate = false;

//Set the compression level to best
doc.CompressionLevel = PdfCompressionLevel.Best;
}

public void CompressImage(PdfDocument doc)
{
//Disable the incremental update
doc.FileInfo.IncrementalUpdate = false;

//Traverse all pages
foreach (PdfPageBase page in doc.Pages)
{
if (page != null)
{
if (page.ImagesInfo != null)
{
foreach (PdfImageInfo info in page.ImagesInfo)
{
page.TryCompressImage(info.Index);
}
}
}
}
}

LauraNM
 
Posts: 77
Joined: Tue Feb 19, 2019 1:23 pm

Thu Sep 09, 2021 10:50 am

Hello,

Thanks for your response.
Sorry that Spire.PDF don’t support directly converting PdfDocumentBase to PdfDocument, you need to save PdfDocumentBase to file or stream and then load it using PdfDocument.

Regarding the issue of "Out of memory", as I mentioned earlier, you need to set the project to run on a 64-bit platform in Visual Studio (as shown in the screenshot) to avoid the 2GB memory usage limit. But if your project is already running on a 64-bit platform and you still get this error, to help us further investigate, please provide some input documents for our reference. You can upload them to the DropBox or OneDrive and then share the download link with us via email(support@e-iceblue.com). Thanks in advance.

screenshot.png
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Return to Spire.Doc