EldoS | Feel safer!

Software components for data protection, secure storage and transfer

System.OutOfMemoryException for PDF Document

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
#10389
Posted: 06/15/2009 08:37:09
by Jonathan Edwards (Basic support level)
Joined: 06/15/2009
Posts: 1

I am trying out several different .Net PDF Assemblies with the intent of compressing PDFs. I have downloaded the trial for PDFBlackbox and am currently experiencing issues with a simple windows application that can open, compress, and then resave a PDF that is over 100MB (117MB to be precise).

As soon as the close method is called, the memory usage in task manager for this simple application spikes up to over 500MB and then an OutOfMemoryException is thrown. I have not experienced this error with any other PDF trial assemblies I have downloaded from other companies. In fact, I have successfully compressed files up to 600MB with no memory exceptions.

Any thoughts on how to prevent this issue?

Code
    Private Sub btnCompressPDF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompressPDF.Click
        loadLicenseKey()

        Dim inPath As String = "C:\PDF\"
        Dim inFile As String = "A.PDF"

        Dim fsPDF As FileStream = New FileStream(inPath + inFile, FileMode.Open, FileAccess.ReadWrite)
        Dim inPDF As New TElPDFDocument

        inPDF.Open(fsPDF)
        inPDF.Compress = True
        inPDF.Close(True)

        MsgBox("Complete")

        inPDF.Dispose()
        fsPDF.Dispose()
    End Sub


Error:
Quote

System.OutOfMemoryException was unhandled
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 SBPDFCore.__Global.WriteArr(Stream s, Byte[] a)
at SBPDFCore.TElPDFFile.Save()
at SBPDF.TElPDFDocument.Close(Boolean Save)
at EldoS_PDFBlackbox.Form1.btnCompressPDF_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\EldoS-PDFBlackbox\EldoS-PDFBlackbox\Form1.vb:line 19
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(Int32 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(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at EldoS_PDFBlackbox.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly 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.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
#10390
Posted: 06/15/2009 08:58:24
by Eugene Mayevski (EldoS Corp.)

Thank you for contacting us.

SecureBlackbox supports PDF compression as a supplementary operation to encryption or signing.

Regarding your question: when the document is loaded, SecureBlackbox builds a DOM-like tree of elements in memory. If the PDF contains a big number of elements or when those elements are compressed (as it happens with many large documents), the memory is not sufficient to build the tree. We are working on this issue now.


Sincerely yours
Eugene Mayevski
#12082
Posted: 01/10/2010 23:45:20
by David Uhl (Basic support level)
Joined: 01/10/2010
Posts: 2

I am having the same problem with running out of memory while password encrypting PDF's. Is there a workaround or solution to this problem yet? We just purchased the software and we frequently process larger files (although 100Megs is not very large in my book).

My first "large" file I tried to encrypt was 170 megs and SBB used eventually used 1.3Gigs of RAM before running out of memory.
#12083
Posted: 01/11/2010 01:01:59
by Eugene Mayevski (EldoS Corp.)

Quote
David Uhl wrote:
We just purchased the software and we frequently process larger files (although 100Megs is not very large in my book).


Please assign the license ticket to your user account as described in the registration e-mail.


Sincerely yours
Eugene Mayevski
#12097
Posted: 01/12/2010 15:14:48
by David Uhl (Basic support level)
Joined: 01/10/2010
Posts: 2

Quote
Eugene Mayevski wrote:
Please assign the license ticket to your user account as described in the registration e-mail.


I created a Help Desk Ticket (I'm assuming that is what you wanted.) I don't have a licensing issue, and I don't see anywhere in my registration e-mail about assigning a license ticket to my user account.
#12098
Posted: 01/13/2010 00:40:02
by Eugene Mayevski (EldoS Corp.)

Answered in helpdesk.


Sincerely yours
Eugene Mayevski
#22032
Posted: 10/16/2012 07:08:11
by Sai Sridhar (Basic support level)
Joined: 10/16/2012
Posts: 1

We have a licensed version of SecureBlackbox.NET. Our main intention is to encrypt a PDF file, and we are able to achieve this for files that are of
lesser size, but the applicaiton fails to load the PDF file of larger size.
The application throws 'System.OutOfMemoryException' exception.
The size of pdf that i'm trying to encrypt is nearly 400MB.
Version of SecureBlackbox.NET that we are using is 8.0.176.21194

The complete stack trace of the error is as below -

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 SBPDFCore.__Global.WriteArr(Stream s, Byte[] a)
at SBPDFCore.TElPDFFile.Save()
at SBPDF.TElPDFDocument.Close(Boolean Save)


Any thoughts on how to get around this issue?
#22033
Posted: 10/16/2012 07:37:23
by Dmytro Bogatskyy (EldoS Corp.)

In this case you should try to handle TElPDFDocument.OnCreateTemporaryStream event, create a temporary file inside the handler, and return the corresponding FileStream object back to the component to work the problem out.
If the event is not handled, a memory stream is internally created and used. This can lead to out-of-memory exceptions on big files.

Please, see:
http://www.eldos.com/documentation/sb...tream.html
#33673
Posted: 06/16/2015 08:36:10
by janjoris van der Lei (Priority Standard support level)
Joined: 08/16/2012
Posts: 14

No idea if this will be seen, but we have the same problem.
I'm using version 12.0.269.0.
I added the following event handlers:
Code

Document.OnCreateTemporaryStream += Document_OnCreateTemporaryStream;
Document.PDFFile.OnCreateTemporaryStream += Document_OnCreateTemporaryStream;


In the handler I put the following code
Code
string sFileName = Path.GetTempFileName();
lstTempFiles.Add(sFileName);
Stream = new FileStream(sFileName, FileMode.Create, FileAccess.ReadWrite);
FreeOnClose = true;


I add the filename to a list<string> to delete these tempfiles after the signing.

When I do document.close(true); the memory rises to the point where I get an out-of-memory exception.

We use a smartcard (eid) to sign the pdf. If I don't include the CA certificate and the CRL and OCSPreply it works fine. But I want the file to be long term valid. So I add the CRL and OCSPRepl. But that makes the memory go up on closing of the document.

Any ideas?
#33676
Posted: 06/16/2015 11:32:58
by Eugene Mayevski (EldoS Corp.)

Dear Janjoris,

it is possible to diagnose the problem if we have the actual data that cause the error as well as the description of your environment. Without such data it's hard to produce any ideas.

Still let's try to at least narrow down the problem.

Please run your signing code under the debugger, set the IDE to stop on managed exceptions (Main menu -> Debug -> Exceptions -> Common Language Runtime exceptions) and when the exception happens, capture the call stack and send it to us.

Maybe it will make more sense to move this topic to the HelpDesk, as we might need or you might accidentally reveal sensitive information.


Sincerely yours
Eugene Mayevski
Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.

Reply

Statistics

Topic viewed 4234 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!