« Xojo August Sale | Home |

Quick encrypt or decrypt with DynaPDF

DynaPDF has a feature to quickly encrypt or decrypt a PDF with the simplified EncryptPDF and DecryptPDF functions. You need an instance of DynaPDFMBS class and then you can call those methods with the right file reference. Pass in the parameters needed like the user password (for viewing) and the owner password (to remove restriction and encryption). We provide several encryption variants, so you can pick the oldest acceptable one. In our example we use 256 bit AES. Here is an example snippet with two example methods:

Sub DecryptPDF(file as Folderitem) Dim pdf As New DynapdfMBS pdf.SetLicenseKey "Lite" // For this example you can use a Lite, Pro or Enterprise License Call pdf.DecryptPDF(File, pdf.kptOwner, "ownerpass") MsgBox "Decrypted." Catch d As DynaPDFErrorExceptionMBS MsgBox "Failed to decrypt PDF: "+d.message End Sub
Sub EncryptPDF(file as Folderitem) Dim pdf As New DynapdfMBS pdf.SetLicenseKey "Lite" // For this example you can use a Lite, Pro or Enterprise License Dim flags As Integer = pdf.krsPrint // forbit printing flags = flags Or pdf.krsCopyObj // deny copying content // userpass to just open and read // ownerpass to decrypt and remove restrictions Call pdf.EncryptPDF(File, "userpass", "ownerpass", pdf.kklAES256, flags) MsgBox "Encrypted." Catch d As DynaPDFErrorExceptionMBS MsgBox "Failed to encrypt PDF: "+d.message End Sub

Please try it, play with the various options on the restrictions. If you make a new PDF with DynaPDF, you can of course also apply the same encryption options for saving the new file. Let us know if you have questions.

06 08 22 - 11:12