Winnovative Software Logo

 HTML to PDF Converter - Excel Library - ASP.NET Charts - RTF to PDF Converter
 PDF Merge and Split - PDF Security - PDF Viewers - PDF to Text - Images Extractor

Skip Navigation Links

Getting Started with PDF Security for .NET



The PDF security for .NET can be used in any type of 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 or 128 bits, remove all the security settings by providing the user or owner password. 

The downloaded archive contains the development libraries for .NET and a ready to use console application in the sample Bin folder. The source code for the command line tool is also available in the Samples folder. You can use this command line tool to change the security settings of the PDF documents.

PDF Security Development Library

The PDF Security develoment library 'wnvsecurepdf.dll' is a managed assembly that can be linked into any .NET application, either Win32 and console applications or ASP.NET web sites. The interface is very easy to be understood and use.

The main class in the assembly 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 exncryption, 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 assembly reference documention in Help.chm document.

First you have to create an instance of the PDFSecurityManager class and then 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.

All the work can be done in a few lines of code.
1: PdfSecurityOptions securityOptions = new PdfSecurityOptions();
3: securityOptions.CanAssembleDocument = canAssembleDocument;
4: securityOptions.CanCopyContent = canCopyContent;
5: securityOptions.CanEditAnnotations = canEditAnnotations;
6: securityOptions.CanEditContent = canEditContent;
7: securityOptions.CanFillFormFields = canFillFormFields;
8: securityOptions.CanPrint = canPrint;
9: securityOptions.KeySize = keySize;
10: securityOptions.UserPassword = userPassword;
11: securityOptions.OwnerPassword = ownerPassword;
13: PdfSecurityManager securityManager =
new PdfSecurityManager(securityOptions);
15: if (removeSecurity)
16:    securityManager.SaveUnSecuredPdfToFile(srcPdfFile, outFile, removeSecurityPswd); 
17: else
18:    securityManager.SaveSecuredPdfToFile(srcPdfFile, outFile);

PDF Security Command Line Tool

  The PDF SecurityCommand 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:

securepdf.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:

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

Remove the security options from the document

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


The license files are expcted to be installed in the same folder with the wnvsecurepdf.dll assembly for the windows forms and console applications. If you want to change this default behavior you have to set the license file path accordingly using LicenseFilePath property of the PDFSecurityManager class.