GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API.

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

See the full code below, use Run Example to execute.

Upload your file(Drag files here)

Download a sample file

using System;
using GemBox.Document;
using GemBox.Document.Drawing;
using System.IO;
using System.Linq;

class Sample
    static void Main(string[] args)
        // If using Professional version, put your serial key below.

        string inputPassword = "inpass";
        string outputPassword = "outpass";
        string ownerPassword = "";

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

        document.Save("PDF Encryption.pdf", options);
Imports System
Imports GemBox.Document
Imports GemBox.Document.Drawing
Imports System.IO
Imports System.Linq

Module Samples

    Sub Main()

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

        Dim inputPassword As String = "inpass"
        Dim outputPassword As String = "outpass"
        Dim ownerPassword As String = ""

        Dim document = DocumentModel.Load("PdfEncryption.pdf", 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 sample.