During post-processing of a PDF we’re running into the exception “Can’t find compressed object”.
Our code is running in .net core 3.1 on windows-x64 using Aspose PDF .NET 20.7.0 crashes on the line that encrypts the PDF. The code looks like this:
using var pdf = new Aspose.Pdf.Document(pdfStream);
// ...create a watermark and add it as a stamp on every page...
var permission = (Aspose.Pdf.Permissions.PrintDocument | Aspose.Pdf.Permissions.PrintingQuality);
pdf.Encrypt(@"", GenerateRandomPassword(), permission, Aspose.Pdf.CryptoAlgorithm.AESx256); // <-- Exception is being thrown here.
The stacktrace seems a bit… obfuscated, it looks like this:
#=zASXAsxoUvkkbTNSl1LHKIkZxGnGTTLLuJXh_4dc=:
at #=zARdq5HoMljL0eCjA$paCIq2qgOGE.#=z9AMEYpo= (Aspose.PDF, Version=20.7.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=zARdq5HoMljL0eCjA$paCIq2qgOGE.#=z9AMEYpo= (Aspose.PDF, Version=20.7.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at Aspose.Pdf.Document.Encrypt (Aspose.PDF, Version=20.7.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
I’ve never seen this bug before, in this case the PDF was supplied by a customer and we don’t know the contents (at this time.) Can you give us any guidance on where this error comes from / how to fix it?
It is hard to say about the reasons behind this issue. We need to replicate the issue in our environment in order to investigate it and for that, we need a sample PDF document. You may save incoming PDF file without encrypting it and share with us with complete code snippet. We will test the scenario in our environment and address it accordingly.
PS: Please also try using Aspose.PDF for .NET 20.8 if it helps.
Please take your time to gather the file which you can share. OR you can share a file in a private message by clicking over username and pressing Blue Message Button.
@asad.ali I’ve sent you a document to reproduce it through a private message.
The unittest that breaks this looks like this:
using var inStream = File.OpenRead(inputFile);
using var doc = new Document(inStream);
doc.Encrypt(@"", "SomePassword", Permissions.PrintDocument |Permissions.PrintingQuality, CryptoAlgorithm.AESx256);
using var outStream = File.Create(outputFile);
doc.Save(outStream);
We have tested the scenario in our environment with Aspose.PDF for .NET 20.11 and were able to notice the similar issue. Therefore, a ticket as PDFNET-49045 has been logged in our issue management system against the issue. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.