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);