DEV Community

Cover image for Automate PDF Signing in .NET MAUI: Sign Once, Fill Everywhere
Calvince Moth for Syncfusion, Inc.

Posted on • Originally published at syncfusion.com on

Automate PDF Signing in .NET MAUI: Sign Once, Fill Everywhere

TL;DR: Stop signing the same document over and over. With Syncfusion’s PDF Viewer for .NET MAUI, you can sign once and automatically apply your signature across all required fields, making PDF processing faster and more accurate.

Tired of signing the same PDF multiple times? Good news, there’s a better way. Document workflows can be time-consuming, especially when dealing with repetitive signatures. With Syncfusion’s powerful PDF Viewer in .NET MAUI, you can streamline the process: sign once and automatically apply the signature to multiple fields throughout the document.

In this blog, we’ll walk you through how to implement this feature step-by-step, helping your users save time and reduce errors while improving overall workflow efficiency.

Introduction to PDF signing

PDF signing allows users to embed a handwritten signature within a PDF document, much like applying a signature on paper. This process is crucial for approvals, acknowledgments, and consent without the bureaucracy of physical paperwork.

Benefits of automating PDF signing

  1. Increased efficiency: Automating the signing process eliminates the need to sign each field individually, significantly speeding up the workflow and allowing users to focus on high-priority tasks.
  2. Improved consistency: Applying a signature uniformly across all relevant fields ensures consistent document signing, with all necessary fields signed using the same visual signature.
  3. Reduced errors: Automated detection and signing across multiple fields reduce the risk of missing required signature fields. This minimizes human error and ensures documents are accurately completed and compliant with signing requirements.

Setting up the environment

To build your automated PDF signing application using .NET MAUI, ensure that your project file includes the necessary Syncfusion.Maui.PdfViewer NuGet package.

Implementing automated PDF signing

To implement automated PDF signing in your .NET MAUI application, follow these steps:

Step 1: Load the PDF form with signature fields

Use SfPdfViewer to open a PDF document that contains multiple pre-defined signature fields. When the user views the document, these fields will be visible and tappable.

Refer to the following code example.

pdfViewer.DocumentSource = typeof(App)
    .GetTypeInfo().Assembly
    .GetManifestResourceStream("YourNamespace.YourForm.pdf");

Enter fullscreen mode Exit fullscreen mode

Note: Before loading the PDF into your .NET MAUI app, ensure that each signature field has a unique and descriptive name (e.g., Tenant Signature, Landlord Signature). A consistent naming convention helps the app identify, group, and automate the signature process for different signer roles. You can also assign names to form fields using the Name property supported by SfPdfViewer.

Step 2: User taps a signature field to sign

When the user taps a signature field, for example, the Tenant role, the SignatureModalViewAppearing event is triggered. In this event, you can store the form field information and suppress the default signature modal to display a custom signature pad view instead. This allows users to create and store signatures more conveniently with simple steps.

To implement this, you can use the SfSignaturePad control.

Refer to the following code examples.

// This wires the SignatureModalViewAppearing event to your handler.
pdfViewer.SignatureModalViewAppearing += pdfViewer_SignatureModalViewAppearing;


private void pdfViewer_SignatureModalViewAppearing(object sender, FormFieldModalViewAppearingEventArgs e)
{
    e.Cancel = true; // Prevent default signature view.
    focusedSignatureFormField = e.FormField; // Store the form field details.
    // Show your custom signature pad here.
}
Enter fullscreen mode Exit fullscreen mode

Step 3: Add the signature to the tapped form field

Once the signature is created, you can add it to the corresponding form field by converting it into an InkAnnotation if point data is available or a StampAnnotation if image data is available. For more details, refer to the documentation on adding signatures to form fields.

In our example, since we used SfSignaturePad, we store the signature as image and add it as StampAnnotation.

// Adds a signature image to a PDF signature form field
async void AddSignToSignatureFormField(FormField formField, ImageSource sign)
{
    // Check if the form field is a signature field
    if (formField is SignatureFormField signatureFormField)
    {
        // Check if the provided signature image is a StreamImageSource
        if (sign is StreamImageSource streamImageSource)
        {
            // Get the image stream from the image source
            Stream? imageStream = await streamImageSource.Stream(CancellationToken.None);
            imageStream.Position = 0; // Reset the stream position before reading

            // Create a new memory stream to copy the image data
            Stream copiedStream = new MemoryStream();
            await imageStream.CopyToAsync(copiedStream); // Copy the image data
            copiedStream.Position = 0; // Ensure the copied stream is at the beginning

            // Create a stamp annotation from the signature image.
            // The RectF determines the location and size (here: X=0, Y=0, Width=300, Height=90).
            StampAnnotation stampAnnotation = new StampAnnotation(
                copiedStream,
                formField.PageNumber,
                new RectF(0, 0, 300, 90))
            {
                IsSignature = true, // Mark this annotation as a signature
            };

            // Assign the stamp annotation as the signature on this form field
            signatureFormField.Signature = stampAnnotation;
        }
    }
}

Enter fullscreen mode Exit fullscreen mode

Step 4: Detect and ask for automating all the relevant signature fields

After the first field is signed, analyze the field name to extract the user role or type, such as Tenant. Then search the document for other signature fields whose names contain the same role or type. This can be achieved using the FormFields property, which provides access to all the form field details in the PDF document.

If matching fields are found, display a confirmation dialog asking the user whether they want to automatically sign all related signature fields.

Refer to the following code example.

string userRole = GetUserRoleFromField(focusedSignatureFormField.Name);

var relevantFields = pdfViewer.FormFields
    .Where(field => field.Name.Contains(userRole) && field is SignatureFormField)
    .Cast();

Enter fullscreen mode Exit fullscreen mode

Step 5: Apply the signature to all matching fields automatically

If the user agrees, apply the same signature annotation to every other unsigned signature field whose name matches the detected user role or type.

Refer to the following code example.

if (applyEverywhere)
{
    foreach (var field in relevantFields)
    {
        if (field.Signature == null)
        {
            AddSignToSignatureFormField(field, signatureImageSource);
        }
    }
}

Enter fullscreen mode Exit fullscreen mode

That’s it! All relevant fields are now signed with the same signature. The user can then review the placements and save or export the document using the functionalities provided by the Syncfusion PDF Viewer.

Refer to the following output image.

<alt-text>


GitHub reference

For more details, refer to the GitHub demo.

Conclusion

And that’s it, you’ve now automated PDF signing in your .NET MAUI app!

By enabling users to sign once and apply across multiple fields using Syncfusion’s PDF Viewer, you’ve made the experience smoother, faster, and more accurate.

Ready to take it further? Explore additional customization, integrate with digital signature certificates, or combine this feature with workflow automation tools to elevate your app even more.

The existing customers can download the new version of Essential Studio on the license and downloads page. If you are not a Syncfusion customer, try our 30-day free trial to check out our incredible features.

Got questions or ideas? Drop them in the comments or contact us through our support forum, support portal, or feedback portal. We are always happy to assist you!

Related Blogs

This article was originally published at Syncfusion.com.

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Tiger Data image

🐯 🚀 Timescale is now TigerData: Building the Modern PostgreSQL for the Analytical and Agentic Era

We’ve quietly evolved from a time-series database into the modern PostgreSQL for today’s and tomorrow’s computing, built for performance, scale, and the agentic future.

So we’re changing our name: from Timescale to TigerData. Not to change who we are, but to reflect who we’ve become. TigerData is bold, fast, and built to power the next era of software.

Read more

👋 Kindness is contagious

Dive into this thoughtful piece, beloved in the supportive DEV Community. Coders of every background are invited to share and elevate our collective know-how.

A sincere "thank you" can brighten someone's day—leave your appreciation below!

On DEV, sharing knowledge smooths our journey and tightens our community bonds. Enjoyed this? A quick thank you to the author is hugely appreciated.

Okay