Hi,
I’m operating on big pdf file (800MB), attached.
I used Aspose.PDF for .NET, version 25.11 and 26.1.
The desired result is to ensure in that file some metadata tags, I prepared 2 versions of code to achieve that.
I cannot use any middle-layer files, so temporary dump to disc is not possible.
The test scripts operates on FileStream, but in my production scenario file is hosted.
1st script works directly on the opened FileStream:
void Main()
{
using (var outputStream = new MemoryStream())
{
// Some source stream, that needs to be loaded to memory afterward
var tempStream = File.OpenRead($@"D:\temp\Test_22_A22222B.pdf");
using (var pdfDocument = new Aspose.Pdf.Document(tempStream))
{
pdfDocument.Info["test"] = "True";
pdfDocument.Save(outputStream);
}
}
}
The exeuction in that scenario is taking a huge amount of time > 40 minutes.
2nd approach:
void Main()
{
using (var outputStream = new MemoryStream())
{
// Some source stream, that needs to be loaded to memory afterward
var tempStream = File.OpenRead($@"D:\temp\Test_22_A22222B.pdf");
using (var processedStream = new MemoryStream())
{
tempStream.CopyTo(processedStream);
processedStream.Position = 0;
using (var pdfDocument = new Aspose.Pdf.Document(processedStream))
{
pdfDocument.Info["test"] = "True";
pdfDocument.Save(outputStream);
}
}
}
}
This operation took ~3,5 minutes, but consumed practiaclly whole available memory during the .Save call.
I’d like to ask:
- If there is any alternate approach to ensure the metadata tag in such big pdf file?
- Is there any alternative approach to .Save call() to reduce the memory utilization in 2nd approach? I cannot modify the content or other properties of pdf file, so OptimizeResources() cannot be used.
- May there be any memory leak issue in .Save() that results in observed behavior?
- I’m having issues with upload of test file, is there some alternative way to provide it to you, or it won’t be needed?
Best regards,
Artur