Sign a big PDF file on 32bit System -- OutOfMemoryException

I was trying to sign a big PDF file, and it throw an OutOfMemoryException. Does document load the whole file into memory? Is there a solution that could make it work on 32bit system?

Exception throws at signature.Save() step.

And my code is nearly the same as examples in Documents ( Digitally sign PDF file | Documentation (aspose.com))
Here is my code:

using (Document document = new Document(tempFile))
{
    using (PdfFileSignature signature = new PdfFileSignature(document))
    {
        var pkcs = new PKCS7(certFile, password); 
        var rect = new System.Drawing.Rectangle(0, 0, Convert.ToInt32(document.Pages[1].PageInfo.Width), 100);
        signature.Sign(1, reason, string.Empty, location, true, rect, pkcs);
        signature.Save(outputFile);
    }
}

@HardToDecide

Please note that it is recommended to use 64-bit mode of debugging in order to process comparatively large files as this way your program has access to all available memory. The API loads complete document into memory in order to process it as it is based upon DOM (Document Object Model) approach. Would you please share your sample PDF document with us so that we can test the scenario in our environment and address it accordingly.

You can upload it to Google Drive or Dropbox and share the link with us.

@asad.ali
Thanks for your reply.

On 32bit system, our product will take some memory (less than 200M), and sign a 400M PDF will throw OutOfMemoryException. I wrote another test example, the test program only has the code mentioned above and is very small. I use the test program to sign a 400M PDF, it work well. And I use it to sign a 600M PDF, it throws the OutOfMemoryException.

400M and 600M are neither special number nor accurate size, I don’t know the limit, I just happened to have these files of these size.

On a 32bit system, except 2G occupied by windows by default, there’s another 2G for us. So even if Aspose API load the complete 600M file into memory, it shouldn’t run out of memory. Is there some duplicates in the memory?

Oh, here is the 600M PDF link : input.pdf - Google Drive

@HardToDecide

Would you please also share the complete stack trace of the exception that you are facing?

@asad.ali

Well…Umm…There just two lines in stack trace window…It’s my test program…

Here is a screen shot
image.png (30.6 KB)

@HardToDecide

There should be complete detailed Stack Trace, please check the attached screenshot. Furthermore, we were able to reproduce the issue at our side as well and logged it in our issue tracking system. We will further look into its details and keep you posted with its rectification status. Please give us some time.

StackTrace.png (26.9 KB)

PS: Please try to share the stack trace information as pointed out in the screenshot.

@asad.ali

Thanks for looking into it.

Here is the stack trace:

" at #=zcWLCjW7aTMS4UofP0LNHV_oCvuo3.#=zTEGTVmo=(String #=zcoEr1QI=, #=zNX6DLyJDjdrYjc595wrprN9i7SvbyozCow== #=zwAfSWT8=, #=zL3Pg8_FaFpl6UcR5dxtZtNF8YxaUe7EhQQ== #=zsWJAal4=, Stream #=zEY_YXTs=, String #=zmEs3Y1c=, #=zwDIyZR3eVrw3dOjMrsVETdpMlMGd #=znoDAiQDqfzVw, TimestampSettings #=zdAgljBSK$nBe, X509Certificate2 #=zdBENPzmmHatX)\r\n at #=zcWLCjW7aTMS4UofP0LNHV_oCvuo3.#=zTEGTVmo=(String #=zcoEr1QI=, #=zNX6DLyJDjdrYjc595wrprN9i7SvbyozCow== #=zwAfSWT8=, #=zL3Pg8_FaFpl6UcR5dxtZtNF8YxaUe7EhQQ== #=zsWJAal4=, Stream #=zEY_YXTs=, String #=zmEs3Y1c=)\r\n at Aspose.Pdf.Forms.Signature.#=zTEGTVmo=(String #=zcoEr1QI=, Stream #=zEY_YXTs=, String #=zmEs3Y1c=)\r\n at Aspose.Pdf.Forms.SignatureField.Sign(Signature signature, Stream pfx, String pass)\r\n at Aspose.Pdf.Forms.SignatureField.Sign(Signature signature)\r\n at Aspose.Pdf.Facades.PdfFileSignature.#=zk5Q3kqinxY3Q(Stream #=zKeJlR8PqGh0X, Stream #=z2FBsO8eihBnP, String #=z$oF49Ig=)\r\n at Aspose.Pdf.Facades.PdfFileSignature.Save(Stream outputStream)\r\n at Aspose.Pdf.Facades.PdfFileSignature.Save(String outputFile)\r\n at AsposeTest.AsposeTest.SignPDF(String src, String dest) in D:\\Work Field\\VStudio\\CSharp\\NASTest\\AsposeTest\\Program.cs:line 60"

@HardToDecide

Thanks for providing the details.

We will look into details of the ticket PDFCPP-1495 on a first come first serve basis and will inform you as soon as it is resolved. Please give us some time.

We are sorry for the inconvenience.