Skip to main content

Sign Documents in DevExpress PDF Viewer for .NET MAUI

  • 3 minutes to read

The DevExpress PDF viewer for .NET MAUI allows you to add handwritten signatures to PDF documents. Signatures are embedded to the document as images.

Add Signature in UI

Follow the steps below to add a signature.

  1. Tap the Sign icon in the edit toolbar.

    DevExpress PDF Viewer for .NET MAUI - Tap Sign icon

  2. In the invoked Signatures bottom sheet, select a signature from the list to insert it or add a new signature.

    DevExpress PDF Viewer for .NET MAUI - List of signatures

  3. The selected signature appears in the center of the page which occupies the most screen space. You can specify the signature’s color, resize it, or move it within the page.

    DevExpress PDF Viewer for .NET MAUI - A signature on the page

  4. To create a new signature, tap Add in the Signatures bottom sheet and free-hand draw the signature in the invoked page.

    DevExpress PDF Viewer for .NET MAUI - Drawing a signature

    Then you can select the newly created signature from the list (See Step 2) to add it on the page.

Add Signature via API

The PDF viewer stores all signatures in the PdfViewer.Signatures collection.

Call the AddSignature method and pass collections of points that compose signature polylines to the method parameters.

<dx:PdfViewer SignatureColor="Black">
    <!--...-->
</dx:PdfViewer>

<dx:DXButton Clicked="DXButton_Clicked" .../>
private void DXButton_Clicked(object sender, EventArgs e) {
    // Add signature points.
    // An origin point (0,0) is the page bottom-left corner; 
    // coordinates are in document units.
    PdfPoint point1 = new PdfPoint(100, 100);
    PdfPoint point2 = new PdfPoint(110, 110);
    PdfPoint point3 = new PdfPoint(120, 100);
    PdfPoint point4 = new PdfPoint(130, 110);
    PdfPoint point5 = new PdfPoint(140, 100);
    PdfPoint point6 = new PdfPoint(150, 150);
    PdfPoint[] points = new[] { point1, point2, point3, point4, point5, point6 };

    List<IList<PdfPoint>> inks = new List<IList<PdfPoint>> { points };

    pdfViewer.AddSignature(1, inks);
}

Call the DeleteSignature method to remove a signature:

pdfViewer.DeleteSignature(pdfViewer.Signatures.First());

You can also specify the list of predefined signatures available in the bottom sheet. Populate the PdfViewer.SignatureStorage.Signatures collection. The following PdfHandwrittenSignatureStorage class methods allow you to load and save signatures:

Signatures should be in JSON format. Review an example:

[[[ {5, 50}, {100, 150}], [{35,16}, {24,12}, {115,110}]], ...]

Save Signatures to the Document

The PDF Viewer does not automatically save newly added signatures to the document. To invoke the system Save File dialog to allow users to save the current document to the file system, call the PdfViewer.ShowSaveFileDialogAsync method or the PdfViewerCommands.ShowSaveFileDialog command. Users can also save documents in the Share UI. To invoke it, call the PdfViewer.ShareDocumentAsync method or the PdfViewerCommands.ShareDocument command. Call the PdfViewer.SaveDocumentAsync method to save the current document to a stream.

After the document is saved, users cannot edit signatures.

Respond to User Actions

SignatureCreating | SignatureCreated
Occur before/after a newly signature object is added on the page.
SignatureChanged
Occurs if a signature object property value is changed. Signature properties cannot be changed after the document is saved since the signature is embedded to the document as a plain image.
SignatureDeleting | SignatureDeleted
Occur before/after a signature is deleted.
SignatureSelectionChanged
Occur a signature is selected/deselected. Users can select signatures before the document is saved.

Prevent Adding Signatures

To prevent signing documents, you can disable the AllowAddSignature property. This disables the Sign icon in the Edit toolbar and the AddSignature method functionality.