Adobe Error 118 - Using Streams- Document.Decrypt and Document.Save(Stream)

Hello, I am using aspose.pdf.dll version 9.7.0.0 in a .Net MVC v4 environment.


I am reading data into an Aspose Document from a file using a FileStream. Once the file has been read into the new memorystream object, I then remove the open document password requirement using the document.decrypt method. After the password has been removed, I then save the document to a MemoryStream and then save that memory stream to another file.

The output file being saved to the filesystem is throwing an adobe error 118 when opened in Acrobat Reader.

I have attached sample files for you to test with and source code samples.

Test5.pdf is my source file, test5b.pdf is the processed file throwing the error 118.

Please advise.

Sample Code:
string decryptPassword = “open”;
                    ms = new MemoryStream();
FileStream inFile = new FileStream(@“c:\users\myuser\desktop\test5.pdf”, FileMode.Open);
inFile.CopyTo(ms);
                <span style="color:green;">// Open the PDF document with the password</span>
                Aspose.Pdf.<span style="color:#2b91af;">Document</span> currentDoc = <span style="color:blue;">new</span> Aspose.Pdf.<span style="color:#2b91af;">Document</span>(ms, decryptPassword);
                currentDoc.Decrypt();
                currentDoc.Save(ms);

                <span style="color:#2b91af;">FileStream</span> outFile = <span style="color:blue;">new</span> <span style="color:#2b91af;">FileStream</span>(<span style="color:#a31515;">@"c:\users\myuser\desktop\test5b.pdf"</span>, <span style="color:#2b91af;">FileMode</span>.Create);
                ms.CopyTo(outFile);
                inFile.Close();
                outFile.Close();
                ms.Close();</pre></div><div><br></div><div>Thank you in advance!</div><div>Rob</div><div><br></div><div><br></div><div><br></div>

Hi Rob,


Thanks for your inquiry. We have manged to notice the reported issue while tested your sample code and document with Aspose.Pdf for .NET 10.3.0. So logged a ticket PDFNEWNET-38588 in our issue tracking system for further investigation and resolution. We will notify you as soon as issue is resolved.

We are sorry for the inconvenience caused.

Best Regards,

Hi Rob,


Thanks for your patience. We have further investigated above issue PDFNEWNET-38588 and suggest you following code snippet for the purpose. It will help you to accomplish the task.

string inputFile = @“C:\test5.pdf”;<o:p></o:p>

string outputFile = @"C:\test5b.pdf";

string decryptPassword = "open";

using (MemoryStream ms = new MemoryStream())

{

using (FileStream inFile = new FileStream(inputFile, FileMode.Open, FileAccess.Read))

{

Aspose.Pdf.Document currentDoc = new Aspose.Pdf.Document(inFile, decryptPassword);

currentDoc.Decrypt();

currentDoc.Save(ms);

File.WriteAllBytes(outputFile, ms.ToArray());

}

}

Please feel free to contact us for any further assistance.


Best Regards,