PDF Encryption in C# and VB.NET

PDF encryption enables you to securely protect the content of your PDF file from unwanted viewers and against unwanted actions like printing, selecting text, etc.

GemBox.Document also supports reading encrypted PDF files.

Following example shows how to convert any document to encrypted PDF file with restricted permissions which requires a password to be decrypted, viewed and, optionally, modified.

Output password and owner password should be specified in the appropriate text box. Input password should also be specified if input PDF file is encrypted.

For more information about PDF encryption in GemBox.Document, see PdfSaveOptions.Permissions remarks.

PDF Encryption Screenshot
Upload your file (Drag file here)
using GemBox.Document;

class Program
    static void Main()
        // If using Professional version, put your serial key below.

        string inputPassword = "%InputPassword%";
        string outputPassword = "%OutputPassword%";
        string ownerPassword = "%OwnerPassword%";

        var document = DocumentModel.Load("%InputFileName%", new PdfLoadOptions() { Password = inputPassword });
        var options = new PdfSaveOptions()
            DocumentOpenPassword = outputPassword,
            PermissionsPassword = ownerPassword,
            Permissions = PdfPermissions.None

        document.Save("PDF Encryption.pdf", options);
Imports GemBox.Document

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.

        Dim inputPassword As String = "%InputPassword%"
        Dim outputPassword As String = "%OutputPassword%"
        Dim ownerPassword As String = "%OwnerPassword%"

        Dim document = DocumentModel.Load("%InputFileName%", New PdfLoadOptions With {.Password = inputPassword})
        Dim options = New PdfSaveOptions() With
            .DocumentOpenPassword = outputPassword,
            .PermissionsPassword = ownerPassword,
            .Permissions = PdfPermissions.None

        document.Save("PDF Encryption.pdf", options)

    End Sub

End Module

Check next example or download examples from GitHub.