We are using Aspose.Pdf.Kit version 126.96.36.199. I am attempting to add a password to a pdf in a memory stream with the following code. However, if I am also using Settings.Strategy = FileProcessingStrategy.OptimizeMemoryUsage, then the file that is created contains garbage.
string inputFileName = @"e:\pdffiles\testinput.pdf";
string outputFileName = @"e:\pdffiles\testoutput.pdf";
string password = "DanLee";
MemoryStream inputStream = new MemoryStream(File.ReadAllBytes(inputFileName));
Settings.Strategy = FileProcessingStrategy.OptimizeMemoryUsage;
MemoryStream encryptedStream = new MemoryStream();
PdfFileSecurity s = new PdfFileSecurity(inputStream, encryptedStream);
s.ChangePassword("", password, password);
I have attached both the input and output files.
If I change this code by removing the Settings.Strategy = statement then the resultant pdf is ok. This is not an option for me. Because the Settings class is global I cannot change the FileProcessingStrategy because it would change the behavior of all the other threads in this process.
Can you suggest a work around that would allow me to add a password to a pdf stream while still keeping my OptimizeMemoryUsage settings?