CreateBookmarks - OutOfMemoryException

Hello,

I’m using Aspose.Pdf.Kit version 5.5.0.0. We are bookmarking our scanned files. Some of them can be more then 500 pages long. I can combine them, no problems. But, we have problems with bookmarking them. We get

“Exception of type System.OutOfMemoryException was thrown.”

when we try to bookmark documents that have more then certain number of pages. Attached example PDF file has 65 pages and 138 MB and CreateBookmarks is failing. Many pdfs we have are bigger then that.

The code I’m using is

Aspose.Pdf.Kit.PdfBookmarkEditor editor = new
Aspose.Pdf.Kit.PdfBookmarkEditor();

editor.BindPdf(pdfFilename);

Aspose.Pdf.Kit.Bookmark bm0 = new
Aspose.Pdf.Kit.Bookmark();

bm0.Action = “GoTo”;

bm0.PageNumber = 1;

bm0.Title = “One bookmark”;

editor.CreateBookmarks(bm0); // <-- OutOfMemoryException

editor.Save(destPdf);

My feeling is that this issue has something to do with file size, not number of pages.

Is there a workaround, or do we have to wait for a fix?

http://www.workido.net/PDFDownload/ThickFile.zip (138 MB)

Thank you,

Dudo

Hello Dudo,

Thanks for using our products.

I have tested the scenario using Aspose.Pdf.Kit for .NET 5.5.0 over windows7 64Bit where my system is Intel Core i5 2.80 GHz with 8GB RAM while using a sample windows application developed in Visual Studio 2008 and as per my observations, the Bookmark is properly being generated and I am unable to notice any problem. Can you please share some more details regarding your working environment. We apologize for your inconvenience.

Hello and thank you for the prompt reply.

My system:

  • Visual Studio 2010
  • Aspose.Pdf.Kit for .NET 5.5.0.0
  • Windows 7 Professional sp1 64 bit
  • Intel Core 2 Duo @ 2.10 GHz
  • 4GB RAM

I attached the full test project. It may help because, in it, you can choose number of scanned pages to create (it just coppies the same page over and over). I included a sample image file (in bin folder) as well. Then it tries to create a bookmark. After certain number of pages, it fails. I hope this will help you to narrow the source of the problem.

Client’s sytem is XP Pro. Don’t know how much RAM they have.

Again, my requirement is to be able to create bookmarks in PDFs. There will be at least one long pdf per day with more then 500 pages.

Please help.

Here is the actual error.

---------------------------------------------------------

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
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 xfc3c9f4b173edcf4.xf2b3414d8422e470.Write(Byte[] b, Int32 offset, Int32 length)
at System.IO.BufferedStream.Flush()
at System.IO.BufferedStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at xfc3c9f4b173edcf4.x29772c3c37b291f5.parseCOSStream(xee8436665878406c dic, Stream file)
at xfc3c9f4b173edcf4.x5aaee8f48ef4defd.x30f085f1ccc05ade()
at xfc3c9f4b173edcf4.x5aaee8f48ef4defd.parse()
at xfc3c9f4b173edcf4.x830721144d567671.xed2598a30006f85f(Stream xcdaeea7afaf570ff)
at Aspose.Pdf.Kit.PdfBookmarkEditor.x14a9fa2bb6069fed()
at Aspose.Pdf.Kit.PdfBookmarkEditor.CreateBookmarks(Bookmark bookmark)
at ThickFile.Form1.btnBookmark_Click(Object sender, EventArgs e) in C:\usr\project\Sjgh-2010\ThickFile\Form1.cs:line 60
at ThickFile.Form1.btnPdf_Click(Object sender, EventArgs e) in C:\usr\project\Sjgh-2010\ThickFile\Form1.cs:line 48
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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.225 (RTMGDR.030319-2200)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
ThickFile
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///P:/Sjgh-2010/ThickFile/bin/Debug/ThickFile.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.225 built by: RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.225 built by: RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Aspose.Pdf
Assembly Version: 5.0.1.0
Win32 Version: 5.0.1.0
CodeBase: file:///P:/Sjgh-2010/ThickFile/bin/Debug/Aspose.Pdf.DLL
----------------------------------------
System.Web
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.225 built by: RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Web/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Web.dll
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.225 built by: RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
Aspose.Pdf.Kit
Assembly Version: 5.5.0.0
Win32 Version: 5.5.0.0
CodeBase: file:///P:/Sjgh-2010/ThickFile/bin/Debug/Aspose.Pdf.Kit.DLL
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
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 xfc3c9f4b173edcf4.xf2b3414d8422e470.Write(Byte[] b, Int32 offset, Int32 length)
at System.IO.BufferedStream.Flush()
at System.IO.BufferedStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at xfc3c9f4b173edcf4.x29772c3c37b291f5.parseCOSStream(xee8436665878406c dic, Stream file)
at xfc3c9f4b173edcf4.x5aaee8f48ef4defd.x30f085f1ccc05ade()
at xfc3c9f4b173edcf4.x5aaee8f48ef4defd.parse()
at xfc3c9f4b173edcf4.x830721144d567671.xed2598a30006f85f(Stream xcdaeea7afaf570ff)
at Aspose.Pdf.Kit.PdfBookmarkEditor.x14a9fa2bb6069fed()
at Aspose.Pdf.Kit.PdfBookmarkEditor.CreateBookmarks(Bookmark bookmark)
at ThickFile.Form1.btnBookmark_Click(Object sender, EventArgs e) in C:\usr\project\Sjgh-2010\ThickFile\Form1.cs:line 60
at ThickFile.Form1.btnPdf_Click(Object sender, EventArgs e) in C:\usr\project\Sjgh-2010\ThickFile\Form1.cs:line 48
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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.225 (RTMGDR.030319-2200)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
ThickFile
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///P:/Sjgh-2010/ThickFile/bin/Debug/ThickFile.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.225 built by: RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.225 built by: RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Aspose.Pdf
Assembly Version: 5.0.1.0
Win32 Version: 5.0.1.0
CodeBase: file:///P:/Sjgh-2010/ThickFile/bin/Debug/Aspose.Pdf.DLL
----------------------------------------
System.Web
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.225 built by: RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Web/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Web.dll
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.225 built by: RTMGDR
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
Aspose.Pdf.Kit
Assembly Version: 5.5.0.0
Win32 Version: 5.5.0.0
CodeBase: file:///P:/Sjgh-2010/ThickFile/bin/Debug/Aspose.Pdf.Kit.DLL
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

Hi Dubravko,

Thank you very much for sharing the sample with us. We’re looking into this issue at our end and you’ll be updated with the results the earliest possible.

We’re sorry for the inconvenience.
Regards,

Hi Dubravko,

The PDF file which is causing the issue is not attached with the post. The link you shared in your first post provides the sample project. Could you please upload the mentioned 138 MB file and share the link?

We’re sorry for the inconvenience.
Regards,

Hi,

Since this looks like a memory related issue I provided a sample project instead of pdf file. Also, some of my PDFs are 200 MB in size. I’m having issues with pdf file produced with that sample project, so rhe sample project will create a pdf file for you. When you compile and run the project you will have only two options:

  1. Create PDF: creates pdf file with specified number of pages. An included jpg is used for this step.

  2. Bookmark PDF: tries to create a bookmark in the previously created pdf file.

Again, we are receiving files with more than 400 pages daily. Some of them are more then 500 pages long. Please create a 500 pages pdf file with my project and try to create a bookmark.

A zip file can be found in previous post or downloaded from http://www.workido.net/PDFDownload/ThickFile.zip

Thank you for your kindness and time.

Dudo

Hi Dudo,

Thank you for sharing further details. We’ll try to reproduce the issue according to your suggestion and get back to you shortly.

Regards,

Hi Dudo,

I have reproduced this problem at my end and logged it as PDFKITNET-28398 in our issue tracking system. Our team will look into this issue and you’ll be updated via this forum thread once it is resolved.

We’re sorry for the inconvenience.
Regards,

Thank you Shahzad. Our client will be grateful when this is done as they are currently putting thick files on a side and waiting for this to be resolved.


Dudo

Hi Dudo,

I’ll contact our team to find the ETA of this issue and you’ll be updated as soon as the response is received.

Regards,

The issues you have found earlier (filed as 28398) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hello. The update is for Aspose.Pdf. The issue was with Aspose.Pdf.Kit. So, I cannot apply this fix for my client.

When will this be fixed in Aspose.Pdf.Kit?

Thank you.

Hi Dubravko,

Thanks for your patience. Since the release of Aspose.Pdf for .NET 6.0.0, the legacy Aspose.Pdf for .NET and Aspose.Pdf.Kit for .NET have been merged into a single product. Now this single component provides the combined capabilities of legacy Aspose.Pdf for .NET and Aspose.Pdf.Kit for .NET. Please note that all the classes of Aspose.Pdf.Kit for .NET are now present under Aspose.Pdf.Facades namespace of Aspose.Pdf for .NET.

As we have already announced, the production of Aspose.Pdf.Kit for .NET is stopped and I am afraid we might not be able to release any new versions/hotfixes for Aspose.Pdf.Kit for .NET. All the issues which were logged against Aspose.Pdf.Kit for .NET, will now be fixed in new versions of Aspose.Pdf for .NET. For more information, please visit the following link

The Last Version of Aspose.Pdf.Kit for .NET is Published

We are really sorry for this inconvenience.

Oh, I see. This may work then. I'll work on it in next few days.

Thank you.