Signature class supports saving signed documents with permission settings and password protection for access and modification. This capability is achieved using the PermissionsPassword and Permissions properties of the PdfSaveOptions class, which should be passed to Sign method.
You can secure a PDF document by setting the following parameters:
Create new instance of Signature class and pass source document path or stream as a constructor parameter.
Instantiate required signature options.
Instantiate the PdfSaveOptions object and specify PermissionsPassword property(optional). Configure the Permissions to control user actions (e.g., deny printing or modification).
Following example demonstrates how to save signed document with permissions.
// Using the Signature class to create a signature for the specified PDF documentusing(Signaturesignature=newSignature("sample.pdf")){TextSignOptionstextSignOptions=newTextSignOptions("JohnSmith"){Left=0,Top=100,Width=100,Height=100,AllPages=true,ForeColor=Color.Black};// Create a new PdfSaveOptions object to configure the PDF save settingsPdfSaveOptionssaveOptions=newPdfSaveOptions();saveOptions.OverwriteExistingFiles=false;// Set permissions to deny printing and modificationsaveOptions.Permissions=Permissions.DenyPrinting|Permissions.DenyModification;// Set a password for modifying permissions(optional)saveOptions.PermissionsPassword="0987654321";// Sign the document and save the result to a new filesignature.Sign("result.pdf",textSignOptions,saveOptions);}
How to load PDF document with permissions
The Signature class supports loading documents with specific permissions that are preserved after signing. This capability is managed through the LoadOptions class, where the Permissions property is set when loading the document. These permissions remain enforced in the signed document, ensuring consistent restrictions from loading to final save output when passed to the Sign method.
To load a PDF document with permissions and ensure those permissions are preserved throughout the signing process, follow these steps:
Create a new instance of LoadOptions , configuring the Permissions property to set restrictions (e.g., deny printing, modification, or data extraction).
Use this LoadOptions instance to initialize the Signature class with the document path or stream.
Instantiate the required signature options (e.g., TextSignOptions ) to set signature position and appearance.
Call the Sign method of the Signature class, passing the signature options. The document will retain the permissions specified in the LoadOptions , ensuring any restrictions applied during loading are preserved in the signed document.
Following example demonstrates how to load PDF document with permissions.
// Set up load options with specific permissions, denying all actions (printing, modification, extraction)LoadOptionsloadOptions=newLoadOptions(){Permissions=Permissions.DenyAll};// Using the Signature class to create a signature for the specified PDF documentusing(Signaturesignature=newSignature("sample.pdf",loadOptions)){TextSignOptionstextSignOptions=newTextSignOptions("JohnSmith"){Left=0,Top=100,Width=100,Height=100};signature.Sign("result.pdf",textSignOptions);}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples: