All docs
V20.2
20.2
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

DocumentSigner.Sign(Stream, Stream, SignatureOptions, SignatureInfo) Method

Signs a file with the specified signature and signature options.

Namespace: DevExpress.Office.DigitalSignatures

Assembly: DevExpress.Docs.v20.2.dll

Declaration

public void Sign(
    Stream inputStream,
    Stream outputStream,
    SignatureOptions options,
    SignatureInfo signatureInfo
)
Public Sub Sign(
    inputStream As Stream,
    outputStream As Stream,
    options As SignatureOptions,
    signatureInfo As SignatureInfo
)

Parameters

Name Type Description
inputStream Stream

The stream that contains a file to sign.

outputStream Stream

The stream to which to save the file.

options SignatureOptions

An object that contains signature options.

signatureInfo SignatureInfo

An object that contains the signature information.

Remarks

Use the Sign method to sign documents and save the result. Office File API supports signatures in the following document formats:

  • Microsoft Word
    • Open XML (DOCX, DOTX, DOTM)
    • 97-2003 (DOC, DOT, DOCM)
  • Microsoft Excel
    • Open XML (XLSX, XLTX, XLSM)
    • 97-2003 binary file (XLS, XLT)
  • Microsoft PowerPoint
    • PPTX, PPT

The SignatureOptions class object allows you to specify validation data (certificate, hash algorithm, timestamp, etc.). Pass the SignatureInfo object to define the signer information.

The options and signatureInfo parameters cannot be null.

The code sample below signs and saves the document:

using DevExpress.Office.DigitalSignatures;
using System;
using System.Diagnostics;
using System.Security.Cryptography.X509Certificates;

static void Main(string[] args)
{
    //Sign a workbook:
    string workbookOutput = "Workbook_signed.xlsx";
    SignDocument("Template.xlsx", workbookOutput);

    //Sign a document:
    string documentOutput = "Document_signed.docx";
    SignDocument("Template.docx", documentOutput);
}
static void SignDocument(string path, string output)
{
    DocumentSigner documentSigner = new DocumentSigner();
    documentSigner.Sign(path, output,
     CreateSignatureOptions(), CreateSignatureInfo());
    Process.Start(output);
}

//Specify a signature certificate and digest method:
static SignatureOptions CreateSignatureOptions()
{
    X509Certificate2 certificate =
     new X509Certificate2("Certificate/SignDemo.pfx", "dxdemo");
    SignatureOptions options = new SignatureOptions();
    options.Certificate = certificate;
    options.DigestMethod = HashAlgorithmType.SHA256;
    return options;
}

//Specify signer information:
static SignatureInfo CreateSignatureInfo()
{
    SignatureInfo signatureInfo = new SignatureInfo();
    signatureInfo.CommitmentType = CommitmentType.ProofOfApproval;
    signatureInfo.Time = DateTime.UtcNow;
    signatureInfo.ClaimedRoles.Clear();
    signatureInfo.ClaimedRoles.Add("Sales Representative");
    signatureInfo.Comments = "Demo Digital Signature";

    return signatureInfo;
}
See Also