Skip to content

Latest commit

 

History

History
60 lines (40 loc) · 3.58 KB

File metadata and controls

60 lines (40 loc) · 3.58 KB

Use the DevExpress Office File API to Draw a Signature and Sign a PDF File

This project uses the .NET MAUI Community Toolkit DrawingView to display a signature pad. This pad allows you to draw your signature and place it in the specified PDF document (using the DevExpress Office File API). Once the file is signed, the app can share the file with other applications.

drawing

Implementation Details

Note

PDF-related functionality described herein requires the DevExpress Office File API or DevExpress Universal Subscription. For purchase/licensing information, please visit devexpress.com.

Our PdfDocumentProcessor class includes APIs designed to modify PDF files.

To open and sign a PDF file in a .NET MAUI application, you must copy PDF and PFX certificate files from the application bundle to a device folder:

public async Task<string> CopyWorkingFilesToAppData(string fileName) {
    using Stream fileStream = await FileSystem.Current.OpenAppPackageFileAsync(fileName);
    string targetFile = Path.Combine(FileSystem.Current.AppDataDirectory, fileName);
    using FileStream outputStream = File.OpenWrite(targetFile);
    fileStream.CopyTo(outputStream);
    return targetFile;
}

Once implemented, you can use the PdfDocumentProcessor.LoadDocument method to open the PDF file.

This project uses the following members to find the first available signature field:

The PDFSignatureBuilder class stores the following information about the signature:

  • PFX certificate file
  • Location of the person who signs the document
  • Name of the person who signs the document
  • Reason for signing the document
  • Signature image that is embedded in the PDF file

This project uses the DrawingView control to draw a signature. To convert a drawn signature to a JPEG image, the project uses the following code:

using Stream origJpgStream = await drawingView.GetImageStream(200, 200);
origJpgStream.Seek(0, SeekOrigin.Begin);
Microsoft.Maui.Graphics.IImage img = PlatformImage.FromStream(origJpgStream, ImageFormat.Jpeg);
var jpegImageBytes = img.AsBytes(ImageFormat.Png);

After the document is signed, the PdfDocumentProcessor.SaveDocument method saves the signed PDF file.

Documentation

More Examples