๐Ÿ”’ Encryption

Password-protected PDFs with AES-256 encryption and granular permission control.

Encrypted PDF
using ObviousPDF;
using ObviousPDF.Accessibility;
using ObviousPDF.Fonts;

var doc = new PdfDocument();
doc.Info.Title = "Encrypted Document";
doc.Language = "en-US";
doc.DisplayDocTitle = true;

doc.Encryption = new PdfEncryption
{
    UserPassword = "",
    OwnerPassword = "AdminPass123",
    Algorithm = PdfEncryptionAlgorithm.Aes256,
    AllowPrinting = true,
    AllowCopying = false,
    AllowModifying = false,
    AllowAnnotating = true
};

var root = doc.EnableTaggedPdf();
var page = doc.AddPage();

var h1 = root.AddChild(StructureType.H1);
page.AddTaggedText(h1, "Encrypted Document", 72, 740,
    new PdfTextOptions { Font = StandardFont.HelveticaBold, FontSize = 20 });

var p = root.AddChild(StructureType.P);
page.AddTaggedTextBlock(p, new[]
{
    "This PDF is encrypted with AES-256.",
    "Anyone can open it (empty user password).",
    "Copying and modifying are restricted.",
    "The owner password 'AdminPass123' grants full access."
}, 72, 700, new PdfTextOptions { FontSize = 12, Leading = 18 });

doc.Save("encrypted.pdf");
Imports ObviousPDF
Imports ObviousPDF.Accessibility
Imports ObviousPDF.Fonts

Dim doc As New PdfDocument()
doc.Info.Title = "Encrypted Document"
doc.Language = "en-US"
doc.DisplayDocTitle = True

doc.Encryption = New PdfEncryption With {
    .UserPassword = "",
    .OwnerPassword = "AdminPass123",
    .Algorithm = PdfEncryptionAlgorithm.Aes256,
    .AllowPrinting = True,
    .AllowCopying = False,
    .AllowModifying = False,
    .AllowAnnotating = True
}

Dim root = doc.EnableTaggedPdf()
Dim page = doc.AddPage()

Dim h1 = root.AddChild(StructureType.H1)
page.AddTaggedText(h1, "Encrypted Document", 72, 740,
    New PdfTextOptions With { .Font = StandardFont.HelveticaBold, .FontSize = 20 })

Dim p = root.AddChild(StructureType.P)
page.AddTaggedTextBlock(p, New String() {
    "This PDF is encrypted with AES-256.",
    "Anyone can open it (empty user password).",
    "Copying and modifying are restricted.",
    "The owner password 'AdminPass123' grants full access."
}, 72, 700, New PdfTextOptions With { .FontSize = 12, .Leading = 18 })

doc.Save("encrypted.pdf")
open ObviousPDF
open ObviousPDF.Accessibility
open ObviousPDF.Fonts

let doc = PdfDocument()
doc.Info.Title <- "Encrypted Document"
doc.Language <- "en-US"
doc.DisplayDocTitle <- true

let enc = PdfEncryption()
enc.UserPassword <- ""
enc.OwnerPassword <- "AdminPass123"
enc.Algorithm <- PdfEncryptionAlgorithm.Aes256
enc.AllowPrinting <- true
enc.AllowCopying <- false
enc.AllowModifying <- false
enc.AllowAnnotating <- true
doc.Encryption <- enc

let root = doc.EnableTaggedPdf()
let page = doc.AddPage()

let h1 = root.AddChild(StructureType.H1)
page.AddTaggedText(h1, "Encrypted Document", 72.0, 740.0,
    PdfTextOptions(Font = StandardFont.HelveticaBold, FontSize = 20.0))

let p = root.AddChild(StructureType.P)
page.AddTaggedTextBlock(p, [|
    "This PDF is encrypted with AES-256."
    "Anyone can open it (empty user password)."
    "Copying and modifying are restricted."
    "The owner password 'AdminPass123' grants full access."
|], 72.0, 700.0, PdfTextOptions(FontSize = 12.0, Leading = 18.0))

doc.Save("encrypted.pdf")
Add-Type -Path "ObviousPDF.dll"

$doc = [ObviousPDF.PdfDocument]::new()
$doc.Info.Title = "Encrypted Document"
$doc.Language = "en-US"
$doc.DisplayDocTitle = $true
$page = $doc.AddPage()
$page.AddText("This document is encrypted.", 72, 720)

$enc = [ObviousPDF.PdfEncryption]::new()
$enc.UserPassword   = ""
$enc.OwnerPassword  = "AdminPass123"
$enc.Algorithm      = [ObviousPDF.PdfEncryptionAlgorithm]::Aes256
$enc.AllowPrinting  = $true
$enc.AllowCopying   = $false
$enc.AllowModifying = $false
$enc.AllowAnnotating = $true
$doc.Encryption = $enc

$doc.Save("c:\temp\encrypted.pdf")
Screenshot of the encrypted PDF in a viewer showing the security padlock icon and a permissions dialog displaying that printing is allowed but copying and modifying are restricted, with AES-256 encryption method indicated

You should see an "Encrypted Document" heading and a four-line paragraph describing the AES-256 settings (open without a password; copying and modifying restricted; owner password required for full access). Check Document Properties โ†’ Security in your viewer to confirm the permissions and encryption algorithm.
File: 11_encryption.pdf

Encryption Options

PropertyDescription
AlgorithmAes128 or Aes256
UserPasswordPassword to open the PDF (empty = no password needed)
OwnerPasswordPassword for full access (change permissions, etc.)
AllowPrintingAllow readers to print
AllowCopyingAllow copy/paste of text
AllowModifyingAllow document editing
AllowAnnotatingAllow adding comments