How to save document with password

Signatureย class supports saving signed document with password protection. This ability is supported overย Passwordย property ofย SaveOptionsย class that should be passed toย Signย method.

Here are the steps to protect signed document with password with GroupDocs.Signature:

  • Create new instance ofย Signatureย class and pass source document path or stream as a constructor parameter.
  • Instantiate required signature options.
  • Instantiate theย SaveOptionsย object and specifyย Passwordย property with required password string.
  • Callย Signย method ofย Signature class instance and pass signatureoptions andย SaveOptionsย objectย to it.

Following example demonstrates how to save signed document with password.

using (Signature signature = new Signature("sample.pdf"))
{
    // create QRCode option with predefined QRCode text
    QrCodeSignOptions signOptions = new QrCodeSignOptions("JohnSmith")
    {
        // setup QRCode encoding type
        EncodeType = QrCodeTypes.QR,
        // set signature position
        Left = 100,
        Top = 100
    };
    SaveOptions saveOptions = new SaveOptions()
    {
        Password = "1234567890",
        UseOriginalPassword = false
    };
    // sign document to file
    signature.Sign("SignedProtected.pdf", signOptions, saveOptions);
}

More resources

GitHub Examples

You may easily run the code above and see the feature in action in ourย GitHub examples:

Free Online Apps

Along with the full-featured .NET library, we provide simple but powerful free online apps.

To sign PDF, Word, Excel, PowerPoint, and other documents you can use the online apps from the GroupDocs.Signature App Product Family.