UserPassword
IPDFDocument4 :: General document management :: Document protection and encryption

See Also Example
Collapse All

This property gets or sets the password for view protection of the PDF document.

Syntax

BSTR UserPassword { get; set; }
Value
String containing the password

Remarks

UserPassword contains a password for the current PDF document. The password is required to view an encrypted PDF file.

Example

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);
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 = 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

See Also

Reference