We are currently deploying Aspose.Pdf.dll V8.5.0.0 to our customers, but the same issue exists in the latest version.
In summary:
• We are building PDF “bundles” of multiple files of differing types, converting them to PDF first, concatenating all PDF’s, adding a table of contents with links and page numbering, among other tasks.
• We took code from this article and built on this although we have a test app where we can recreate this issue Concatenate PDF documents in C#|Aspose.PDF for .NET and are experiencing System.OutOfMemoryException on larger files.
• The actual concatenation of the files is quick and easy, but the memory isn’t released well afterwards. After the concatenation, the OutOfMemoryException has been seen to occur at lines :
o concatenated_pdfDocument.Save(Document_With_BlankPage); or
o fileStamp.Save(Document_with_TOC_Heading);
• Originally we believed this issue was due to our customer having larger than expected PDF files, (>60MB, 2 page scans) but when they scanned these at a more appropriate resolution the problem still occurs, but the issue is “postponed” until the resulting concatenated PDF is larger.
• In addition, if page numbering is selected, a System.IO.IOException can also be thrown, but only on large files again.
• By way of an example, a sample bundle I have
o contains 31 files ranging from 10KB to 62MB, with a total pre-concatenated size of 242MB
o the concatenate produces a single PDF of 241MB
• The exception details are below
Is there a better way we should be doing this, or is there a limitation as to the file sizes that we should be handling? Any help much appreciated.
System.OutOfMemoryException was unhandled
HResult=-2147024882
Message=Exception of type ‘System.OutOfMemoryException’ was thrown.
Source=mscorlib
StackTrace:
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.BinaryWriter.Write(Byte[] buffer, Int32 index, Int32 count)
at . . (Byte[] , Int32 , Int32 )
at . . . ( , , Boolean , Int64& )
at . . . ( , )
at . . ( , , Boolean , Int64& )
at . . ( , )
at . . . ( , , Boolean , Int64& )
at . . . ( streamWriter, pdfPrimitive, Int64& offset)
at . . ( , , Boolean , Int64& )
at . . ( streamWriter, pdfPrimitive, Int64& offset)
at . . ( , )
at . . ()
at . .Save(Stream )
at . .Save(Stream )
at Aspose.Pdf.Document.Save(Stream output)
at Aspose.Pdf.Facades.SaveableFacade.Save(Stream destStream)
at Aspose.Pdf.Facades.PdfFileStamp.Save(Stream destStream)
at AsposeTest.frmMain.CreateConcatenatedPDFFile(String[] pdfFiles) in C:\src\Product Team\AsposeTest\Form1.cs:line 863
at AsposeTest.frmMain.btnCombine_Click(Object sender, EventArgs e) in C:\src\Product Team\AsposeTest\Form1.cs:line 557
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at AsposeTest.Program.Main() in C:\src\Product Team\AsposeTest\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: