Home arrow Samples arrow Split Document Make Text BiggerMake Text SmallerReset Text Size
Protected Document

This sample shows how to protect a document with a password.

// Get a fresh copy of the sample PDF file
string filename = "HelloWorld.pdf";
File.Copy(Path.Combine("../../../../PDFs/", filename), 
  Path.Combine(Directory.GetCurrentDirectory(), filename), true);
// Open an existing document. Providing an unrequired password is ignored.
PdfDocument document = PdfReader.Open(filename, "some text");
PdfSecuritySettings securitySettings = document.SecuritySettings;
// Setting one of the passwords automatically sets the security level to 
// PdfDocumentSecurityLevel.Encrypted128Bit.
securitySettings.UserPassword  = "user";
securitySettings.OwnerPassword = "owner";
// DonĀ“t use 40 bit encryption unless needed for compatibility reasons
//securitySettings.DocumentSecurityLevel = PdfDocumentSecurityLevel.Encrypted40Bit;
// Restrict some rights.
securitySettings.PermitAccessibilityExtractContent = false;
securitySettings.PermitAnnotations = false;
securitySettings.PermitAssembleDocument = false;
securitySettings.PermitExtractContent = false;
securitySettings.PermitFormsFill = true;
securitySettings.PermitFullQualityPrint = false;
securitySettings.PermitModifyDocument = true;
securitySettings.PermitPrint = false;
// Save the document...
// ...and start a viewer.
< Prev   Next >
New! We no longer maintain this site. Visit the new PDFsharp and MigraDoc Foundation Homepage. © 2009 empira Software GmbH | Impressum | Created with Joomla!