Hi,
We are using Aspose.PDF .NET to programmatically encrypt a PDF document but we are encountering an error upon save. This only happens in our client and not in our development environment. Any thoughts on this? Here’s our code looks like:
Public Sub SetSecurityAndSave(fileName As String, password As String, printingAllowed As Boolean, contentModifyingAllowed As Boolean, copyingAllowed As Boolean, contentsModifyingAllowed As Boolean,
-
annotationsModifyingAllowed As Boolean, formFillingAllowed As Boolean, screenReadersAllowed As Boolean, documentAssemblyingAllowed As Boolean)*
-
Dim privilege As DocumentPrivilege = DocumentPrivilege.ForbidAll*
-
With privilege*
-
.AllowPrint = printingAllowed*
-
.PrintAllowLevel = 1*
-
.AllowModifyContents = contentModifyingAllowed*
-
.AllowCopy = copyingAllowed*
-
.AllowModifyContents = contentModifyingAllowed*
-
.AllowFillIn = formFillingAllowed*
-
.AllowScreenReaders = screenReadersAllowed*
-
.AllowAssembly = documentAssemblyingAllowed*
-
End With*
-
'open PDF document*
-
Dim fileSecurity As New PdfFileSecurity(doc)*
-
'set document privileges*
-
If Not String.IsNullOrEmpty(password) Then*
-
Try*
-
fileSecurity.EncryptFile(password, "deltek", privilege, KeySize.x128)*
-
Catch ex As Exception*
-
Throw New Framework.Errors.Common.FrameworkException("fileSecurity.EncryptFile: " & ex.Message)*
-
End Try*
-
Else*
-
Try*
-
fileSecurity.SetPrivilege(privilege)*
-
Catch ex As Exception*
-
Throw New Framework.Errors.Common.FrameworkException("fileSecurity.SetPrivilege: " & ex.Message)*
-
End Try*
-
End If*
-
Try*
-
fileSecurity.Save(fileName)*
-
Catch ex As Aspose.Pdf.Exceptions.InvalidPasswordException*
-
Throw New Framework.Errors.Common.FrameworkException("Aspose.Pdf.Exceptions.InvalidPasswordException: " & ex.Message)*
-
Catch ex As Exception*
-
Throw New Framework.Errors.Common.FrameworkException("fileSecurity.Save: " & ex.Message)*
-
End Try*
-
End Sub*
The exception happens when it calls the filesecurity.save() and it throws the error “Invalid Password”.
Class:
___. Ť ___
Function:
Initialize
FrameworkException:
Invalid password
Here are the values passed in the method: printingAllowed = true, screenReadersAllowed =true, eveything else false. Password is simple, something like ‘11111998’. We even tried ‘foobar’ and it still throws the same error.
We also have this in the code but the error is not trapped here but on the Throw New Framework.Errors.Common.FrameworkException("fileSecurity.Save: " & ex.Message)
Catch ex As Aspose.Pdf.Exceptions.InvalidPasswordException
-
Throw New Framework.Errors.Common.FrameworkException("Aspose.Pdf.Exceptions.InvalidPasswordException: " & ex.Message)*
We are using Aspose.PDF version 10.6.