Click or drag to resize
Getting Started with ExpertPdf PDF Security Library for .NET

The ExpertPdf PDF Security Library for .NET can be used in any type of .NET application to manage the security settings of the PDF documents. You can encrypt the PDF content, add user and owner passwords, control the PDF document permissions for printing, copying, assembling, filling forms, editing content, editing annotations, etc or you can specify the length of the encryption key to 40, 128 or 256 bits, the encryption algorithm to RC4 or AES or remove all the security settings by providing the user or owner password.

The product archive contains the development libraries for .NET 2.0 and .NET 4.0 and a ready to use console application in the Samples folder, written in C# and VB.NET. You can use this command line tool to change the security settings of the PDF documents.

PDF Security Development Library

The PDF Security development library epsecurepdf.dll is a managed assembly that can be linked into any .NET application, either Windows Forms and console applications or ASP.NET 2.0 or 4.0 web sites. The interface is very easy to be use and understand.

The main class in the library is PdfSecurityManager. An instance of this class can be constructed by specifying the security options as an instance of the PdfSecurityOptions class or using the default security options (no password protection, no encryption, allow printing, allow editing content, allow copying, allow edit annotations, 128 bit encryption key). If you need to change any of these settings, you have to pass a PdfSecurityOptions object to the PdfSecurityManager constructor. For a complete reference of the assembly classes and methods see the API section in this manual.

After you have created an instance of the PdfSecurityManager class, then you need to call the methods to apply or remove the security options for the PDF document. All the methods have versions working for the memory representation of the PDF document as an array of bytes or for PDF files. The memory versions of the methods can be used to easily interface with the other PDF tools producing PDF documents in memory.

When you want to apply or remove the security options you can simply call the methods like GetSecuredPdfBytes and GetUnSecuredPdfBytes.

The library is very easy to use. Here is a simple code sample:
PdfSecurityOptions securityOptions = new PdfSecurityOptions();

securityOptions.CanAssembleDocument = canAssembleDocument;
securityOptions.CanCopyContent = canCopyContent;
securityOptions.CanEditAnnotations = canEditAnnotations;
securityOptions.CanEditContent = canEditContent;
securityOptions.CanFillFormFields = canFillFormFields;
securityOptions.CanPrint = canPrint;

securityOptions.KeySize = EncryptionKeySize.EncryptKey256Bit;
securityOptions.Algorithm = EncryptionAlgorithm.AES;

securityOptions.UserPassword = userPassword;
securityOptions.OwnerPassword = ownerPassword;

PdfSecurityManager securityManager = new PdfSecurityManager(securityOptions);

if (removeSecurity) {
    securityManager.SaveUnSecuredPdfToFile(srcPdfFile, outFile, removeSecurityPswd);
else {
    securityManager.SaveSecuredPdfToFile(srcPdfFile, outFile);
PDF Security Command Line Tool

The PDF Security Command Line Tool is a simple application constructed based on the development libraries. It is also a ready to use application in case you don't need to build your own application. The command line syntax is:

SecurePDFDemo.exe /pdf:source_pdf_file [/noassembly] [/nocopy] [/noeditannot] [/noeditcontent] [/nofillform] [/noprint] [/keysize: (40|128)] [/userpswd:user_password] [/ownerpswd:owner_password] [/removesecurity] /out:out_pdf_file

In simple terms, this syntax means that you can specify the source pdf file, the user and owner passwords in case you want to encrypt the document, the document permisions. You can also specify the /removesecurity and the user or owner password in case you want to remove all the security options. The out file is used to determine where to write the PDF document with the security options applied.

Command line example:

Set user and owner passwords:

SecurePDFDemo.exe /noprint /keysize:128 /ownerpswd:myownerpswd /userpswd:myuserpswd /out:SecuredDocument.pdf

Remove the security options from the document:

SecurePDFDemo.exe /userpswd:myuserpswd /removesecurity /out:UnSecuredDocument.pdf


The LicenseKey property of the PdfSecurityManager class should be set with the license key string you have received after the product purchase.