Protecting a PDF Document
Delphi
[copy to clipboard]
{ PDF object is supposed to be created }
PDF.ShowText('Here is my secret text.');
PDF.OwnerPassword := '!2C4e';
PDF.UserPassword := '12345';
PDF.DocumentEncryption := el128bitRC4;
{ set permissions }
PDF.AllowChangeDocument := DisallowChanges;
PDF.AllowCopyContent := DisallowCopy;
PDF.AllowPrintDocument := DisallowPrint;
{ all this could be set in one line: }
{ PDF.SetSecurityFlagsRaw($FFFFF0C0); }
{ Now our document is protected }
PDF.SaveToFile('test.pdf', true);
C/C++
[copy to clipboard]
// PDF object is supposed to be created
PDF->ShowText("Here is my secret text.");
PDF->OwnerPassword = "!2C4e";
PDF->UserPassword = "12345";
PDF->DocumentEncryption = el128bitRC4;
// set permissions
PDF->AllowChangeDocument = DisallowChanges;
PDF->AllowCopyContent = DisallowCopy;
PDF->AllowPrintDocument = DisallowPrint;
//all this could be set in one line:
//PDF.SetSecurityFlagsRaw(0xFFFFF0C0);
// Now our document is protected
PDF->SaveToFile("test.pdf", true);
// PDF object is supposed to be created
PDF.ShowText("Here is my secret text.");
PDF.OwnerPassword = "!2C4e";
PDF.UserPassword = "12345";
PDF.DocumentEncryption = EncryptionLevel.el128bitRC4;
// set permissions
PDF.AllowChangeDocument = AllowedChanges.DisallowChanges;
PDF.AllowCopyContent = AllowedCopyLevel.DisallowCopy;
PDF.AllowPrintDocument = AllowedPrintQuality.DisallowPrint;
//all this could be set in one line:
//PDF.SetSecurityFlagsRaw(0xFFFFF0C0);
// Now our document is protected
PDF.SaveToFile("test.pdf", true);
Visual Basic
[copy to clipboard]
' PDF object is supposed to be created
PDF.ShowText "Here is my secret text."
PDF.OwnerPassword = "!2C4e"
PDF.UserPassword = "12345"
PDF.DocumentEncryption = 1 ' EncryptionLevel.el128bitRC4
' set permissions
PDF.AllowChangeDocument = 0 ' AllowedChanges.DisallowChanges
PDF.AllowCopyContent = 0 ' AllowedCopyLevel.DisallowCopy
PDF.AllowPrintDocument = 0 'AllowedPrintQuality.DisallowPrint
'all this could be set in one line:
'PDF.SetSecurityFlagsRaw(&HFFFFF0C0);
' Now our document is protected
PDF.SaveToFile "test.pdf", true