RAD PDF - Interactive Demonstrations

RAD PDF supports signatures in a variety of ways:
  1. Typed Signature With Cursive Font
    You can use a custom signature font and a simple text form field (or text shape) to give your user a convenient place to type his or her signature. The user simply needs to click the object and type! This sample shows how to setup RAD PDF to use the open source font Herr Von Muellerhoff both as a web font and PDF file processing to facilitate typed signatures.
  2. Image Based Signature
    You can use an image to represent a signature. The user can upload images via the GUI or you can use a more customized integration like this one which loads a specific signature file from the server based on the key passed to our Client API. This sample shows how to use the PdfImageShape to place signature images at the click of a button.
  3. Mouse / Touch Signatures
    RAD PDF also offers a signature shape object which allows the user to draw a signature in a specific region of the page. The user can use a mouse or touch device to sign. This signature is captured as vector and flattened directly into the PDF on save. This example shows a basic implementation with a border.
  4. Signature Popup
    RAD PDF's signature shape object can also be used with a popup to add a signature in a specific region of the page. The user can use a mouse or touch device to sign, typed text input, or an uploaded image. This example shows a basic implementation with a border.
When saving or printing, the PdfIntegrationProvider implementation adds a timestamp to each page. Also, notice that the hint text under each signature example is set to be hidden when output to PDF (.OutputToPDF = false) or print (.Print = false). This allows custom instructions or content to selectively appear in your documents.

RAD PDF can also certify and timestamp PDF documents using a digital certificate.

RAD PDF Sample Source Files

Default.aspx

<%@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="RadPdf" Namespace="RadPdf.Web.UI" TagPrefix="radPdf" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <script type="text/javascript">
        function initRadPdf()
        {
            // Get id
            var id = "<%= PdfWebControl1.ClientID%>";

            // Get api instance
            var api = new PdfWebControlApi(id);

            // Function for finding object by customData
            function findObject(s)
            {
                for( var i = 1; i <= api.getPageCount(); i++ )
                {
                    var p = api.getPage(i);

                    for( var j = 0; j < p.getObjectCount(); j++ )
                    {
                        var o = p.getObject(j);

                        if( o.getProperties()["customData"] == s )
                        {
                            return o;
                        }
                    }
                }
            }

            // Attach listeners
            api.addEventListener(
            api.addEventListener(
                "objectChanged", 
                function(evt) {
                    // Get properties of changed object
                    var props = evt.obj.getProperties();

                    // If the popup signature was changed (or signed)
                    if( "MyPopupSignature" == props.customData )
                    {
                        // Change popup hint if signed
                        var msg = props.isSigned ? "thank you for signing!" : "click above to sign via popup"

                        // Update hint object
                        findObject("MyPopupHint").setProperties( { "text" : msg } );
                    }
                }
                );
            api.addEventListener(
                "objectClicked", 
                function(evt) {
                    // If this is our special image signature object
                    if( "MyImageSignature" == evt.obj.getProperties()["customData"] )
                    {
                        // Set the image via key
                        evt.obj.setImage("MyImageSignature");
                    }
                }
                );
        }
    </script>

    <title>RAD PDF Sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <radPdf:PdfWebControl id="PdfWebControl1" runat="server" height="600px" width="100%" OnClientLoad="initRadPdf();"
            HideToolsTabs="true" HideObjectPropertiesBar="true" HideBookmarks="true" HideThumbnails="true" />
    </div>
    </form>
</body>
</html>

Default.aspx.cs

using System;
using System.Drawing;
using System.IO;
using System.Web.UI.HtmlControls;

using RadPdf.Data.Document;
using RadPdf.Data.Document.Common;
using RadPdf.Data.Document.Objects;
using RadPdf.Data.Document.Objects.FormFields;
using RadPdf.Data.Document.Objects.Shapes;
using RadPdf.Data.Document.Pages;

partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Create new document for DEMO
            this.PdfWebControl1.CreateDocument("Document_Name", 1, PdfPageSize.Letter, PdfDocumentSettings.FlattenForm);

            // NOTE: To use PdfWebControlLite instead, change <radPdf:PdfWebControl ... to <radPdf:PdfWebControlLite ... in the .aspx file and replace the above line with:
            // RadPdf.Lite.PdfLiteSettings settings = new RadPdf.Lite.PdfLiteSettings();
            // settings.DocumentSettings = PdfDocumentSettings.FlattenForm;
            // this.PdfWebControl1.CreateDocument("Document_Name", 1, PdfPageSize.Letter, settings);

            // Setup document editor
            PdfDocumentEditor editor = this.PdfWebControl1.EditDocument();

            int dpi = Convert.ToInt32(editor.Document.Dpi);

            // Create custom font form field example (It will be flattened on save. Replace "PdfDocumentSettings.FlattenForm" with "PdfDocumentSettings.None" above to prevent this.)
            PdfTextField field = editor.Pages[0].CreateObject(PdfObjectCreatable.FormFieldText) as PdfTextField;
            field.Top = dpi;
            field.Left = 3 * dpi / 4;
            field.Width = dpi * 2;
            field.Height = dpi / 2;
            field.Font.Name = "Signature";
            field.Font.Size = dpi / 4;
            field.Deletable = false;
            field.Duplicatable = false;
            field.Moveable = false;
            field.Name = "MySignatureField";
            field.Resizable = false;
            field.Stylable = false;

            // Create image example
            PdfImageShape image = editor.Pages[0].CreateObject(PdfObjectCreatable.ShapeImage) as PdfImageShape;
            image.Top = dpi;
            image.Left = 13 * dpi / 4;
            image.Width = dpi * 2;
            image.Height = dpi / 2;
            image.CustomData = "MyImageSignature";
            image.Deletable = false;
            image.Duplicatable = false;
            image.Moveable = false;
            image.Resizable = false;
            image.Stylable = false;
            image.ImageData = File.ReadAllBytes(Server.MapPath(@"/demo/images/empty.gif"));

            // Create signature shape example
            PdfSignatureShape signature = editor.Pages[0].CreateObject(PdfObjectCreatable.ShapeSignature) as PdfSignatureShape;
            signature.Top = dpi;
            signature.Left = 23 * dpi / 4;
            signature.Width = dpi * 2;
            signature.Height = dpi / 2;
            signature.Border = new PdfBorder(2, PdfBorderStyle.Solid, new PdfColor(Color.Black));
            signature.PenColor = new PdfColor(Color.Blue);
            signature.PenWidth = 2;

            // Create signature shape popup example
            PdfSignatureShape signaturePopup = editor.Pages[0].CreateObject(PdfObjectCreatable.ShapeSignature) as PdfSignatureShape;
            signaturePopup.Top = 2 * dpi;
            signaturePopup.Left = 13 * dpi / 4;
            signaturePopup.Width = dpi * 2;
            signaturePopup.Height = dpi / 2;
            signaturePopup.Border = new PdfBorder(2, PdfBorderStyle.Solid, new PdfColor(Color.Black));
            signaturePopup.CustomData = "MyPopupSignature";
            signaturePopup.Font.Name = "Signature";
            signaturePopup.Font.Size = dpi / 4;
            signaturePopup.PenColor = new PdfColor(Color.Blue);
            signaturePopup.PenWidth = 2;
            signaturePopup.PopupInput = true;

            // Create hints
            PdfTextShape fHint = editor.Pages[0].CreateObject(PdfObjectCreatable.ShapeText) as PdfTextShape;
            fHint.Top = 5 + 3 * dpi / 2;
            fHint.Left = 3 * dpi / 4;
            fHint.Width = dpi * 2;
            fHint.Height = dpi / 4;
            fHint.Font.Name = "Arial";
            fHint.Font.Size = dpi / 8;
            fHint.Changeable = false;
            fHint.Deletable = false;
            fHint.Duplicatable = false;
            fHint.HideFocusOutline = true;
            fHint.Moveable = false;
            fHint.OutputToPDF = false;
            fHint.Print = false;
            fHint.Resizable = false;
            fHint.Stylable = false;
            fHint.Text = "type a signature";
            fHint.Wrappable = false;

            PdfTextShape iHint = editor.Pages[0].CreateObject(PdfObjectCreatable.ShapeText) as PdfTextShape;
            iHint.Top = 5 + 3 * dpi / 2;
            iHint.Left = 13 * dpi / 4;
            iHint.Width = dpi * 2;
            iHint.Height = dpi / 4;
            iHint.Font.Name = "Arial";
            iHint.Font.Size = dpi / 8;
            iHint.Changeable = false;
            iHint.Deletable = false;
            iHint.Duplicatable = false;
            iHint.HideFocusOutline = true;
            iHint.Moveable = false;
            iHint.OutputToPDF = false;
            iHint.Print = false;
            iHint.Resizable = false;
            iHint.Stylable = false;
            iHint.Text = "click above to sign via image";
            iHint.Wrappable = false;

            PdfTextShape sHint = editor.Pages[0].CreateObject(PdfObjectCreatable.ShapeText) as PdfTextShape;
            sHint.Top = 5 + 3 * dpi / 2;
            sHint.Left = 23 * dpi / 4;
            sHint.Width = dpi * 2;
            sHint.Height = dpi / 4;
            sHint.Font.Name = "Arial";
            sHint.Font.Size = dpi / 8;
            sHint.Changeable = false;
            sHint.Deletable = false;
            sHint.Duplicatable = false;
            sHint.HideFocusOutline = true;
            sHint.Moveable = false;
            sHint.OutputToPDF = false;
            sHint.Print = false;
            sHint.Resizable = false;
            sHint.Stylable = false;
            sHint.Text = "draw a signature with your mouse";
            sHint.Wrappable = false;

            PdfTextShape pHint = editor.Pages[0].CreateObject(PdfObjectCreatable.ShapeText) as PdfTextShape;
            pHint.Top = 5 + 5 * dpi / 2;
            pHint.Left = 13 * dpi / 4;
            pHint.Width = dpi * 2;
            pHint.Height = dpi / 4;
            pHint.CustomData = "MyPopupHint";
            pHint.Font.Name = "Arial";
            pHint.Font.Size = dpi / 8;
            pHint.Changeable = false;
            pHint.Deletable = false;
            pHint.Duplicatable = false;
            pHint.HideFocusOutline = true;
            pHint.Moveable = false;
            pHint.OutputToPDF = false;
            pHint.Print = false;
            pHint.Resizable = false;
            pHint.Stylable = false;
            pHint.Text = "click above to sign via popup";
            pHint.Wrappable = false;

            // Save changes
            editor.Save();
        }
    }
}

web.config


<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="RadPdfConnectionString" value="Server=.\SQLExpress;Database=RadPdf;Trusted_Connection=Yes;"/>
    <add key="RadPdfIntegrationProvider" value="SignaturesPdfIntegrationProvider,App_Code"/>
    <add key="RadPdfLicenseKey" value="DEMO"/>
  </appSettings>
  <system.web>
    <httpHandlers>
      <add path="RadPdf.axd" verb="GET,POST" type="RadPdf.Web.HttpHandler.PdfHttpHandler"/>
    </httpHandlers>
  </system.web>
  <!--
    The system.webServer element is for use with IIS 7 (and later) when Managed Pipeline Mode is set to "Integrated".
    It will be ignored in other versions of IIS.
    -->
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
      <add path="RadPdf.axd" verb="GET,POST" name="PdfHttpHandler" preCondition="integratedMode" type="RadPdf.Web.HttpHandler.PdfHttpHandler"/>
    </handlers>
  </system.webServer>
</configuration>

App_Code\SignaturesPdfIntegrationProvider.cs


using System;
using System.Drawing;
using System.Web;

using RadPdf.Data.Document;
using RadPdf.Data.Document.Common;
using RadPdf.Data.Document.Objects;
using RadPdf.Data.Document.Objects.Shapes;
using RadPdf.Data.Document.Pages;
using RadPdf.Integration;

public class SignaturesPdfIntegrationProvider : PdfIntegrationProvider
{
    public SignaturesPdfIntegrationProvider()
        : base()
    {
        // Add the signature font of our choice.
        // This example uses Herr Von Muellerhoff which is an open source font (SIL Open Font License, Version 1.1).
        // Herr Von Muellerhoff must be installed on your server. The TrueType file is provided by Google here:
        // https://github.com/google/fonts/tree/master/ofl/herrvonmuellerhoff
        this.FontResources.Add(new PdfFontResource("Signature", "Herr Von Muellerhoff, cursive, serif", "Herr Von Muellerhoff"));
    }

    private static void ApplyTimestamp(PdfDocument document, string timestampText)
    {
        const string TimestampCustomData = "timestamp";

        int dpi = Convert.ToInt32(document.Dpi);

        // Add our watermark on each page
        foreach (PdfPage p in document.Pages)
        {
            PdfTextShape timestamp = FindOnPage(p, TimestampCustomData) as PdfTextShape;

            // If not found
            if (null == timestamp)
            {
                timestamp = p.CreateObject(PdfObjectCreatable.ShapeText) as PdfTextShape;

                // Set custom data so we can find it next save and re-use it
                timestamp.CustomData = TimestampCustomData;
            }

            // Set position
            timestamp.Left = 0;
            timestamp.Top = dpi * 3;
            timestamp.Height = dpi / 2;
            timestamp.Width = p.Width;
            timestamp.Rotation = PdfRotation.Rotation0;

            // Set properties
            timestamp.Changeable = false;
            timestamp.Deletable = false;
            timestamp.Duplicatable = false;
            timestamp.HideFocusOutline = true;
            timestamp.Moveable = false;
            timestamp.Resizable = false;
            timestamp.Stylable = false;
            timestamp.Wrappable = true;

            // Set font
            timestamp.Font.Alignment = PdfHorizontalAlignment.AlignCenter;
            timestamp.Font.Color = new PdfColor(Color.Red);
            timestamp.Font.Size = dpi / 3;

            // Set text
            timestamp.Text = timestampText;
        }
    }

    private static PdfObject FindOnPage(PdfPage page, string searchForCustomData)
    {
        foreach (PdfObject o in page.Objects)
        {
            if (o.CustomData == searchForCustomData)
            {
                return o;
            }
        }

        return null;
    }

    public override void OnDocumentInit(DocumentInitEventArgs e)
    {
        base.OnDocumentInit(e);

        //Add web font for client side fall back if Herr Von Muellerhoff isn't installed on clients.
        // (fonts.bunny.net is a more privacy conscious option vs. fonts.googleapis.com)
        e.ExternalStyle = "https://fonts.bunny.net/css?family=Herr+Von+Muellerhoff";

        // Or to use Google Fonts:
        // e.ExternalStyle = "https://fonts.googleapis.com/css?family=Herr+Von+Muellerhoff";
    }

    public override void OnDocumentPrinting(DocumentPrintingEventArgs e)
    {
        base.OnDocumentPrinting(e);

        string timestampText = "Last Printed " + DateTime.UtcNow.ToString();

        ApplyTimestamp(e.Document, timestampText);
    }

    public override void OnDocumentSaving(DocumentSavingEventArgs e)
    {
        base.OnDocumentSaving(e);

        string timestampText = "Last Saved " + DateTime.UtcNow.ToString();

        ApplyTimestamp(e.Document, timestampText);
    }

    public override void OnDocumentSaved(DocumentSavedEventArgs e)
    {
        base.OnDocumentSaved(e);

        // Reload the document client side after saving
        e.ThenReloadDocument = true;
    }

    public override void ProcessObjectDataRequest(PdfDataContext context)
    {
        switch (context.Request.DataKey)
        {
            case "MyImageSignature":
                // Write a file to the response
                // Alternatively, we could also use the .Write method to write data from almost any source (e.g. database, memory, etc.)
                context.Response.WriteFile(HttpContext.Current.Server.MapPath("/demo/images/signature.gif"));
                break;
        }
    }
}

Default.aspx

<%@ Page Language="VB" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Register Assembly="RadPdf" Namespace="RadPdf.Web.UI" TagPrefix="radPdf" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <script type="text/javascript">
        function initRadPdf()
        {
            // Get id
            var id = "<%= PdfWebControl1.ClientID%>";

            // Get api instance
            var api = new PdfWebControlApi(id);

            // Function for finding object by customData
            function findObject(s)
            {
                for( var i = 1; i <= api.getPageCount(); i++ )
                {
                    var p = api.getPage(i);

                    for( var j = 0; j < p.getObjectCount(); j++ )
                    {
                        var o = p.getObject(j);

                        if( o.getProperties()["customData"] == s )
                        {
                            return o;
                        }
                    }
                }
            }

            // Attach listeners
            api.addEventListener(
            api.addEventListener(
                "objectChanged", 
                function(evt) {
                    // Get properties of changed object
                    var props = evt.obj.getProperties();

                    // If the popup signature was changed (or signed)
                    if( "MyPopupSignature" == props.customData )
                    {
                        // Change popup hint if signed
                        var msg = props.isSigned ? "thank you for signing!" : "click above to sign via popup"

                        // Update hint object
                        findObject("MyPopupHint").setProperties( { "text" : msg } );
                    }
                }
                );
            api.addEventListener(
                "objectClicked", 
                function(evt) {
                    // If this is our special image signature object
                    if( "MyImageSignature" == evt.obj.getProperties()["customData"] )
                    {
                        // Set the image via key
                        evt.obj.setImage("MyImageSignature");
                    }
                }
                );
        }
    </script>

    <title>RAD PDF Sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <radPdf:PdfWebControl id="PdfWebControl1" runat="server" height="600px" width="100%" OnClientLoad="initRadPdf();"
            HideToolsTabs="true" HideObjectPropertiesBar="true" HideBookmarks="true" HideThumbnails="true" />
    </div>
    </form>
</body>
</html>

Default.aspx.vb

Option Explicit On
Option Strict On

Imports System
Imports System.Drawing
Imports System.IO
Imports System.Web.UI.HtmlControls

Imports RadPdf.Data.Document
Imports RadPdf.Data.Document.Common
Imports RadPdf.Data.Document.Objects
Imports RadPdf.Data.Document.Objects.FormFields
Imports RadPdf.Data.Document.Objects.Shapes
Imports RadPdf.Data.Document.Pages

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then

            ' Create new document for DEMO (It will be flattened on save. Replace PdfDocumentSettings.FlattenForm with PdfDocumentSettings.None to prevent this.)
            Me.PdfWebControl1.CreateDocument("Document_Name", 1, PdfPageSize.Letter, PdfDocumentSettings.FlattenForm)

            ' NOTE: To use PdfWebControlLite instead, change <radPdf:PdfWebControl ... to <radPdf:PdfWebControlLite ... in the .aspx file and replace the above line with:
            ' Dim settings As RadPdf.Lite.PdfLiteSettings = New RadPdf.Lite.PdfLiteSettings()
            ' settings.DocumentSettings = PdfDocumentSettings.FlattenForm
            ' Me.PdfWebControl1.CreateDocument("Document_Name", 1, PdfPageSize.Letter, settings)

            ' Setup document editor
            Dim editor As PdfDocumentEditor = Me.PdfWebControl1.EditDocument()

            Dim dpi as Integer = Convert.ToInt32(editor.Document.Dpi)

            ' Create custom font form field example (It will be flattened on save. Replace "PdfDocumentSettings.FlattenForm" with "PdfDocumentSettings.None" above to prevent this.)
            Dim field As PdfTextField = DirectCast(editor.Pages(0).CreateObject(PdfObjectCreatable.FormFieldText), PdfTextField)
            field.Top = dpi
            field.Left = 3 * dpi \ 4
            field.Width = dpi * 2
            field.Height = dpi \ 2
            field.Font.Name = "Signature"
            field.Font.Size = dpi \ 4
            field.Deletable = False
            field.Duplicatable = False
            field.Moveable = False
            field.Name = "MySignatureField"
            field.Resizable = False
            field.Stylable = False

            ' Create image example
            Dim image As PdfImageShape = DirectCast(editor.Pages(0).CreateObject(PdfObjectCreatable.ShapeImage), PdfImageShape)
            image.Top = dpi
            image.Left = 13 * dpi \ 4
            image.Width = dpi * 2
            image.Height = dpi \ 2
            image.CustomData = "MyImageSignature"
            image.Deletable = False
            image.Duplicatable = False
            image.Moveable = False
            image.Resizable = False
            image.Stylable = False
            image.ImageData = File.ReadAllBytes(Server.MapPath("/demo/images/empty.gif"))

            ' Create signature shape example
            Dim signature As PdfSignatureShape = DirectCast(editor.Pages(0).CreateObject(PdfObjectCreatable.ShapeSignature), PdfSignatureShape)
            signature.Top = dpi
            signature.Left = 23 * dpi \ 4
            signature.Width = dpi * 2
            signature.Height = dpi \ 2
            signature.Border = new PdfBorder(2, PdfBorderStyle.Solid, new PdfColor(Color.Black))
            signature.PenColor = new PdfColor(Color.Blue)
            signature.PenWidth = 2

            ' Create signature shape popup example
            Dim signaturePopup As PdfSignatureShape = DirectCast(editor.Pages(0).CreateObject(PdfObjectCreatable.ShapeSignature), PdfSignatureShape)
            signaturePopup.Top = 2 * dpi
            signaturePopup.Left = 13 * dpi \ 4
            signaturePopup.Width = dpi * 2
            signaturePopup.Height = dpi \ 2
            signaturePopup.Border = new PdfBorder(2, PdfBorderStyle.Solid, new PdfColor(Color.Black))
            signaturePopup.CustomData = "MyPopupSignature"
            signaturePopup.Font.Name = "Signature"
            signaturePopup.Font.Size = dpi / 4
            signaturePopup.PenColor = new PdfColor(Color.Blue)
            signaturePopup.PenWidth = 2
            signaturePopup.PopupInput = true

            ' Create hints
            Dim fHint As PdfTextShape = DirectCast(editor.Pages(0).CreateObject(PdfObjectCreatable.ShapeText), PdfTextShape)
            fHint.Top = 3 * dpi \ 2
            fHint.Left = 3 * dpi \ 4
            fHint.Width = dpi * 2
            fHint.Height = dpi \ 4
            fHint.Font.Name = "Arial"
            fHint.Font.Size = dpi \ 8
            fHint.Changeable = False
            fHint.Deletable = False
            fHint.Duplicatable = False
            fHint.HideFocusOutline = True
            fHint.Moveable = False
            fHint.OutputToPDF = False
            fHint.Print = False
            fHint.Resizable = False
            fHint.Stylable = False
            fHint.Text = "type a signature"
            fHint.Wrappable = False

            Dim iHint As PdfTextShape = DirectCast(editor.Pages(0).CreateObject(PdfObjectCreatable.ShapeText), PdfTextShape)
            iHint.Top = 3 * dpi \ 2
            iHint.Left = 13 * dpi \ 4
            iHint.Width = dpi * 2
            iHint.Height = dpi \ 4
            iHint.Font.Name = "Arial"
            iHint.Font.Size = dpi \ 8
            iHint.Changeable = False
            iHint.Deletable = False
            iHint.Duplicatable = False
            iHint.HideFocusOutline = True
            iHint.Moveable = False
            iHint.OutputToPDF = False
            iHint.Print = False
            iHint.Resizable = False
            iHint.Stylable = False
            iHint.Text = "click above to sign via image"
            iHint.Wrappable = False

            Dim sHint As PdfTextShape = DirectCast(editor.Pages(0).CreateObject(PdfObjectCreatable.ShapeText), PdfTextShape)
            sHint.Top = 3 * dpi \ 2
            sHint.Left = 23 * dpi \ 4
            sHint.Width = dpi * 2
            sHint.Height = dpi \ 4
            sHint.Font.Name = "Arial"
            sHint.Font.Size = dpi \ 8
            sHint.Changeable = False
            sHint.Deletable = False
            sHint.Duplicatable = False
            sHint.HideFocusOutline = True
            sHint.Moveable = False
            sHint.OutputToPDF = False
            sHint.Print = False
            sHint.Resizable = False
            sHint.Stylable = False
            sHint.Text = "draw a signature with your mouse"
            sHint.Wrappable = False

            Dim pHint As PdfTextShape = DirectCast(editor.Pages(0).CreateObject(PdfObjectCreatable.ShapeText), PdfTextShape)
            pHint.Top = 5 + 5 * dpi \ 2
            pHint.Left = 13 * dpi \ 4
            pHint.Width = dpi * 2
            pHint.Height = dpi \ 4
            pHint.CustomData = "MyPopupHint"
            pHint.Font.Name = "Arial"
            pHint.Font.Size = dpi / 8
            pHint.Changeable = False
            pHint.Deletable = False
            pHint.Duplicatable = False
            pHint.HideFocusOutline = True
            pHint.Moveable = False
            pHint.OutputToPDF = False
            pHint.Print = False
            pHint.Resizable = False
            pHint.Stylable = False
            pHint.Text = "click above to sign via popup"
            pHint.Wrappable = False

            ' Save changes
            editor.Save()

        End If
    End Sub
End Class

web.config


<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="RadPdfConnectionString" value="Server=.\SQLExpress;Database=RadPdf;Trusted_Connection=Yes;"/>
    <add key="RadPdfIntegrationProvider" value="SignaturesPdfIntegrationProvider,App_Code"/>
    <add key="RadPdfLicenseKey" value="DEMO"/>
  </appSettings>
  <system.web>
    <httpHandlers>
      <add path="RadPdf.axd" verb="GET,POST" type="RadPdf.Web.HttpHandler.PdfHttpHandler"/>
    </httpHandlers>
  </system.web>
  <!--
    The system.webServer element is for use with IIS 7 (and later) when Managed Pipeline Mode is set to "Integrated".
    It will be ignored in other versions of IIS.
    -->
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
      <add path="RadPdf.axd" verb="GET,POST" name="PdfHttpHandler" preCondition="integratedMode" type="RadPdf.Web.HttpHandler.PdfHttpHandler"/>
    </handlers>
  </system.webServer>
</configuration>

App_Code\SignaturesPdfIntegrationProvider.vb

Option Explicit On
Option Strict On

Imports System
Imports System.Drawing
Imports System.Web

Imports RadPdf.Data.Document
Imports RadPdf.Data.Document.Common
Imports RadPdf.Data.Document.Objects
Imports RadPdf.Data.Document.Objects.Shapes
Imports RadPdf.Data.Document.Pages
Imports RadPdf.Integration

Public Class SignaturesPdfIntegrationProvider
    Inherits PdfIntegrationProvider

    Public Sub New()
        MyBase.New()

        ' Add the signature font of our choice.
        ' This example uses Herr Von Muellerhoff which is an open source font (SIL Open Font License, Version 1.1).
        ' Herr Von Muellerhoff must be installed on your server. The TrueType file is provided by Google here:
        ' https://github.com/google/fonts/tree/master/ofl/herrvonmuellerhoff
        Me.FontResources.Add(new PdfFontResource("Signature", "Herr Von Muellerhoff, cursive, serif", "Herr Von Muellerhoff"))

    End Sub

    Private Shared Sub ApplyTimestamp(ByVal document As PdfDocument, ByVal timestampText As String)

        Const TimestampCustomData As String = "timestamp"

        Dim dpi As Integer = Convert.ToInt32(document.Dpi)

        ' Add our watermark on each page
        For Each p As PdfPage In document.Pages

            Dim timestamp As PdfTextShape = DirectCast(FindOnPage(p, TimestampCustomData), PdfTextShape)

            ' If not found
            If (timestamp Is Nothing) Then
                timestamp = DirectCast(p.CreateObject(PdfObjectCreatable.ShapeText), PdfTextShape)

                ' Set custom data so we can find it next save and re-use it
                timestamp.CustomData = TimestampCustomData
            End If

            ' Set position
            timestamp.Left = 0
            timestamp.Top = dpi * 3
            timestamp.Height = dpi \ 2
            timestamp.Width = p.Width
            timestamp.Rotation = PdfRotation.Rotation0

            ' Set properties
            timestamp.Changeable = False
            timestamp.Deletable = False
            timestamp.Duplicatable = False
            timestamp.HideFocusOutline = True
            timestamp.Moveable = False
            timestamp.Resizable = False
            timestamp.Stylable = False
            timestamp.Wrappable = True

            ' Set font
            timestamp.Font.Alignment = PdfHorizontalAlignment.AlignCenter
            timestamp.Font.Color = new PdfColor(Color.Red)
            timestamp.Font.Size = dpi \ 3

            ' Set text
            timestamp.Text = timestampText
        Next

    End Sub

    Private Shared Function FindOnPage(ByVal page As PdfPage, ByVal searchForCustomData As String) As PdfObject

        For Each o As PdfObject In page.Objects

            If (o.CustomData = searchForCustomData) Then

                Return o

            End If
        Next

        Return Nothing

    End Function

    Public Overrides Sub OnDocumentInit(ByVal e As DocumentInitEventArgs)
        MyBase.OnDocumentInit(e)

        'Add Web font for client side
        ' (fonts.bunny.net is a more privacy conscious option vs. fonts.googleapis.com)
        e.ExternalStyle = "https://fonts.bunny.net/css?family=Herr+Von+Muellerhoff"

        ' Or to use Google Fonts:
        ' e.ExternalStyle = "https://fonts.googleapis.com/css?family=Herr+Von+Muellerhoff"
    End Sub

    Public Overrides Sub OnDocumentPrinting(ByVal e As DocumentPrintingEventArgs)
        MyBase.OnDocumentPrinting(e)

        Dim timestampText As String = "Last Printed " & DateTime.UtcNow.ToString()

        ApplyTimestamp(e.Document, timestampText)
    End Sub

    Public Overrides Sub OnDocumentSaving(ByVal e As DocumentSavingEventArgs)
        MyBase.OnDocumentSaving(e)

        Dim timestampText As String = "Last Saved " & DateTime.UtcNow.ToString()

        ApplyTimestamp(e.Document, timestampText)
    End Sub

    Public Overrides Sub OnDocumentSaved(ByVal e As DocumentSavedEventArgs)
        MyBase.OnDocumentSaved(e)

        ' Reload the document client side after saving
        e.ThenReloadDocument = true
    End Sub

    Public Overrides Sub ProcessObjectDataRequest(ByVal context As PdfDataContext)

        Select context.Request.DataKey

            Case "MyImageSignature"
                ' Write a file to the response
                ' Alternatively, we could also use the .Write method to write data from almost any source (e.g. database, memory, etc.)
                context.Response.WriteFile(HttpContext.Current.Server.MapPath("/demo/images/signature.gif"))

        End Select
    End Sub

End Class
RAD PDF is a Red Software product - ©2007-2024 Red Software