While saving with PdfFileSignature object by .save() method is throwing System.OutOfMemoryException.
Would you please share your complete sample code snippet along with used source files. We will test the scenario in our environment and address it accordingly.
please find below code:
public void SignPdf(string keyPath, string mergedPdf, string tempDirectory)
{
// Document pdfDocument = new Document(mergedPdf);
//byte[] data = File.ReadAllBytes(mergedPdf);
//MemoryStream stream = new MemoryStream(data);
Document pdfDocument = new Document(mergedPdf);
string outputPdfName = Path.Combine(tempDirectory, "Output_Signed.pdf");
PdfFileSignature pdfSign = new PdfFileSignature();
pdfSign.BindPdf(pdfDocument);
Rectangle rect = new Rectangle(390, 280, 0, 60);
PKCS7 signature = new PKCS7(keyPath, config.PdfSignPassword);
pdfSign.Sign(1, string.Empty, config.PdfSignContact, config.PdfSignLocation, true, rect, signature);
TextAbsorber absorber = new TextAbsorber(new TextExtractionOptions(TextExtractionOptions.TextFormattingMode.MemorySaving));
using (pdfDocument = new Aspose.Pdf.Document(mergedPdf))
{
foreach (Page page in pdfDocument.Pages)
{
page.Accept(absorber);
page.Dispose();
}
string text = absorber.Text;
pdfSign.Save(outputPdfName);
GC.Collect();
pdfDocument.Dispose();
RenameFile(outputPdfName, mergedPdf);
}
}
Our application deployed on Microsoft azure as app service.for small files upto 200mb its working fine but for 500mb files its throwing System.OutOfMemoryException.
Would you please also share a sample PDF document for our reference as we tested using one of our sample PDF document and were unable to replicate the exception. We used our sample certificate file during testing. You may upload your sample files (PDF and Certificate file) to Dropbox or Google Drive and share the link with us.
I can give you sample file which we used to upload while testing & you can use your sample certificate file with this file.
here is link:
We were able to observe the issue in our environment while using Aspose.PDF for .NET 20.10 with your file. We have logged it as PDFNET-48901 in our issue management system for the sake of further analysis. We will look into its details and keep you informed with the status of its rectification. Please be patient and spare us some time.
We are sorry for the inconvenience.
The issues you have found earlier (filed as PDFNET-48901) have been fixed in Aspose.PDF for .NET 20.12.