Hi Team,
I’m trying to call PdfFileSecurity.SetPrivilege() on a un protected PDF. It works on windows, but throws InvalidPasswordException: Invalid password on Linux. The PDF has no password and and no restrictions. It seems to do with the Aspose.Pdf dll behaviour on linux.
- Aspose.Pdf.dll version 23.10;
- Program is in .Net 6.0
- Linux is AWS Linux 2023
Below is the code
using Aspose.Pdf;
using Aspose.Pdf.Facades;
namespace Aspose_Test
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World 2!");
byte[] fileBytes = File.ReadAllBytes("1.pdf");
using (var stream = new MemoryStream())
{
Document doc = new Document(new MemoryStream(fileBytes));
PdfFileSecurity security = new PdfFileSecurity(doc);
security.SetPrivilege(DocumentPrivilege.AllowAll);
MemoryStream ms = new MemoryStream();
doc.Save("Stamped.pdf");
}
}
}
}
The exception is as below
Unhandled exception. Aspose.Pdf.InvalidPasswordException: Invalid password
at Aspose.Pdf.Facades.PdfFileSecurity.#=zNz8cPTk=(String #=zWJQsCRve_Yq7, String #=zGrpZU75v1aFM, String #=zibRqVugVTUK0, Permissions #=zK0vt0qc=, CryptoAlgorithm #=zWm5Op8bEneev, Boolean #=zcjXr7W9hfG32)
at Aspose.Pdf.Facades.PdfFileSecurity.EncryptFile(String userPassword, String ownerPassword, DocumentPrivilege privilege, KeySize keySize)
at Aspose.Pdf.Facades.PdfFileSecurity.SetPrivilege(DocumentPrivilege privilege)
at Aspose_Test.Program.Main(String[] args) in E:\_Temp\Aspose Test\Aspose Test\Program.cs:line 18
Is there a solution to fix it? Please advise.
Thanks in advance.
@mailzhengli
In the Linux, would you please try to using Aspose.Pdf.Drawing. Please remove Aspose.PDF for .NET from your project and install Aspose.Pdf.Drawing instead. It will work without any code change in your both Windows and Linux environments. If you still face any issues, please let us know.
I have the same problem, I am runing the APOSE.PDF.dll on Windows 2022 Server and get same error: Invalid Password eventhough we paid for the license.
Anyone know why?
@tony.dong
Would you please share your sample PDF document with us along with the minimal sample code snippet? We will test the scenario in our environment and address it accordingly.
Hi There
Here is my code and I can’t upload the PDF due to it include sensitive data, the file size around 4 MB. This problem is not always happening.
Public Sub AddPdfStamp(pdfPath As String, stampFolder As String)
Using pdfDocument As New Document(pdfPath)
Dim lowerLeftX As Integer = 30
Dim upperRightX As Integer = 150
Dim lowerLeftY As Integer = 700
Dim upperRightY As Integer = 770
Using page As Page = pdfDocument.Pages(1)
Using imageStream As New FileStream(stampFolder & “StampWithDate.png”, FileMode.Open)
page.Resources.Images.Add(imageStream)
page.Contents.Add(New Aspose.Pdf.Operators.GSave())
Dim rectangle As Aspose.Pdf.Rectangle = New Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY)
Dim matrix As Aspose.Pdf.Matrix = New Aspose.Pdf.Matrix(New Double() {rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY})
page.Contents.Add(New Aspose.Pdf.Operators.ConcatenateMatrix(matrix))
Dim ximage As XImage = page.Resources.Images(page.Resources.Images.Count)
page.Contents.Add(New Aspose.Pdf.Operators.Do)
page.Contents.Add(New Aspose.Pdf.Operators.GRestore())
pdfDocument.Save(pdfPath)
End Using
End Using
End Using
End Sub
Hi All
I found one reason, the PDF is password protected and that maybe is the reason I got Invalid Password, I think we can close this.
Thanks
@tony.dong
Yes, that must be the reason. You need to provide valid password in order to initialize a Document with password-protected PDF. Please feel free to create a new topic in case you face any other issues.