PDF Toolkit

Samples

Set PDF Security

Set security and other access permissions to a PDF document

This Code sample requires the PDF Toolkit and is found in: C:\Aquaforest\PDF Toolkit\samples\SetPDFPermissions


using Aquaforest.PDF;

namespace SetPDFPermissions
{
    class Program
    {
        static void Main(string[] args)
        {
            PDFDocument doc = new PDFDocument(@"..\..\..\documents\source\releasenotes.pdf");
    
            PDFPermission permission = new PDFPermission()
            {
                AllowExtractContents = false,
                AllowModifyContents = false,
                AllowAssembly = true,
                AllowDegradedPrinting = true,
                AllowExtractForAccessibility = true,
                AllowFillInForm = false,
                AllowModifyAnnotations = false,
                AllowPrinting = true
            };
    
            PDFSecurity encryptor = new PDFSecurity()
            {
                Permission = permission,
                OwnerPassword = "myOwnerPassword",
                UserPassword = "myUserPassword"
            };
    
            encryptor.SecurePDF(doc, @"..\..\..\documents\output\secure_pdf.pdf");
        }
    }
}