Document Extraction

This guide will go over how to use the document extraction feature to extract the fields in your document.

The document extraction feature automatically creates all signatures and fields that exist in an uploaded PDF file. The positions and sizes of the signatures and fields in the PDF file are automatically retained in OneSpan Sign.

Configuring the PDF Form Fields

First, you will need a PDF with form fields, named how OneSpan Sign can recognize them. You can see more about the proper format of the form field names in the documentation. Below is the PDF document that is used in this guide. The form field names on the fields are shown in the image below.

formFieldPDF

As you can see, the two signers on the document will be “Signer1” and “Preparer1”. These will be the custom IDs used in the code section below to let OneSpan Sign know what fields to associate with each signer.

The Code

This segment of the guide only shows snippets of code. You can download the full sample code from the Developer Community Code Share, here.

The sample code below shows you how to setup your document package (transaction in the new UI) for document extraction. In each “withSigner” call, you will see that the custom IDs coincide with the ones in the image of the PDF form shown earlier in the guide. The .withDocument also has a call to “enableExtraction”. Because this is done, you might notice that you do not have to define the signature locations and who needs to sign the document. This is already taken care of with the IDs and the associated form field names from the PDF.

DocumentPackage superDuperPackage = newPackageNamed("Test Document Extraction")
            	.withSettings(newDocumentPackageSettings())
            	.withSigner(newSignerWithEmail("signer.email@example.com" )
                    	.withCustomId("Signer1")
                    	.withFirstName("John")
                    	.withLastName("Smith"))
            	.withSigner(newSignerWithEmail("preparer.email@example.com")
                    	.withFirstName("Michael")
                    	.withLastName("Williams")
                    	.withCustomId("Preparer1"))
            	.withDocument(newDocumentWithName("testDocumentExtraction")
                    	.fromStream(documentStream, DocumentType.PDF)
                    	.enableExtraction())
            	.build();

What it looks like

After running your code, the package is created with the appropriate fields for each signer. This is what Signer1 will see:

formFieldPDFPackageSignerView

As you see, the required fields are highlighted for the user to fill out. The Name field will be filled in automatically by OneSpan Sign when the signing is complete.

Likewise, the preparer sees this:

formFieldPDFPackagePreparerView

Get the Code

The document extraction feature automatically creates all signatures and fields that exist in an uploaded PDF file. The positions and sizes of the signatures and fields in the PDF file are automatically retained in OneSpan Sign.

Configuring the PDF Form Fields

First, you will need a PDF with form fields, named how OneSpan Sign can recognize them. You can see more about the proper format of the form field names in the documentation. Below is the PDF document that is used in this guide. The form field names on the fields are shown in the image below.

formFieldPDF

As you can see, the two signers on the document will be “Signer1” and “Preparer1”. These will be the custom IDs used in the code section below to let OneSpan Sign know what fields to associate with each signer.

The Code

This segment of the guide only shows snippets of code. You can download the full sample code from the Developer Community Code Share, here.

The sample code below shows you how to setup your document package (transaction in the new UI) for document extraction. In each “withSigner” call, you will see that the custom IDs coincide with the ones in the image of the PDF form shown earlier in the guide. The .withDocument also has a call to “enableExtraction”. Because this is done, you might notice that you do not have to define the signature locations and who needs to sign the document. This is already taken care of with the IDs and the associated form field names from the PDF.

DocumentPackage superDuperPackage = PackageBuilder.NewPackageNamed("Test Document Extraction")
                .WithSettings(DocumentPackageSettingsBuilder.NewDocumentPackageSettings())
                    .WithSigner(SignerBuilder.NewSignerWithEmail("signer.email@example.com")
                                .WithFirstName("John")
                                .WithLastName("Smith")
                                .WithCustomId("Signer1")
                    )
                    .WithSigner(SignerBuilder.NewSignerWithEmail("preparer.email@example.com")
                                .WithFirstName("Michael")
                                .WithLastName("Williams")
                                .WithCustomId("Preparer1")
                    )
                    .WithDocument(DocumentBuilder.NewDocumentNamed("testDocumentExtraction")
                                  .FromStream(fileStream1, DocumentType.PDF)
                                  .EnableExtraction()
                                 )
                    .Build();

What it looks like

After running your code, the package is created with the appropriate fields for each signer. This is what Signer1 will see:

formFieldPDFPackageSignerView

As you see, the required fields are highlighted for the user to fill out. The Name field will be filled in automatically by OneSpan Sign when the signing is complete.

Likewise, the preparer sees this:

formFieldPDFPackagePreparerView

Get the Code

The document extraction feature automatically creates all signatures and fields that exist in an uploaded PDF file. The positions and sizes of the signatures and fields in the PDF file are automatically retained in OneSpan Sign.

Configuring the PDF Form Fields

First, you will need a PDF with form fields, named how OneSpan Sign can recognize them. You can see more about the proper format of the form field names in the documentation. Below is the PDF document that is used in this guide. The form field names on the fields are shown in the image below.

formFieldPDF

As you can see, the two signers on the document will be “Signer1” and “Preparer1”. These will be the custom IDs used in the code section below to let OneSpan Sign know what fields to associate with each signer.

The Code

This segment of the guide only shows snippets of code. You can download the full sample code from the Developer Community Code Share, here.

Typically, you will probably build your JSON string dynamically versus having a giant static string, like this. This is to give a good representation of the structure of the JSON you will need to create your package (transaction in the new UI) properly. The JSON below is formatted for readability.

In each “roles” object, you will see that the custom IDs coincide with the ones in the image of the PDF form shown earlier in the guide. The “documents” object also has “extract” to true. Because this is done, you might notice that you do not have to define the signature locations and who needs to sign the document. This is already taken care of with the IDs and the associated form field names from the PDF.

HTTP Request
POST /api/packages

HTTP Headers
Accept: application/json
Content-Type: multipart/form-data
Authorization: Basic api_key

Request Payload

------WebKitFormBoundary1bNO60n7FqP5WO4t
Content-Disposition: form-data; name="file"; filename="testDocumentExtraction.pdf"
Content-Type: application/pdf

%PDF-1.5
%µµµµ
1 0 obj
<>>>
endobj.... 

------WebKitFormBoundary1bNO60n7FqP5WO4t
Content-Disposition: form-data; name="payload"

{
    	"roles":[
    	{
            	"id":"Preparer1",
            	"type":"SIGNER",
            	"signers":[
            	{
                    	"firstName":"Michael",
                    	"lastName":"Williams",
                    	"phone":"",
                    	"email":"preparer.email@example.com",
                    	"delivery":
                    	{
                            	"email":true,
                            	"provider":false,
                            	"download":true
                    	},
                    	"id":"Preparer1"
            	}],
            	"name":"Sender"
    	},
    	{
            	"id":"Signer1",
            	"type":"SIGNER",
            	"signers":[
            	{
                    	"firstName":"John",
                    	"lastName":"Smith",
                    	"email":"signer.email@example.com",
                    	"delivery":
                    	{
                            	"email":false,
                            	"provider":false,
                            	"download":false
                    	},
                    	"id":"Signer1"
            	}],
            	"name":"Signer"
    	}],
    	"documents":[
    	{
            	"name": "testDocumentExtraction",
             	"extract": true
    	}],
    	"name": "Test Document Extraction",
    	"type":"PACKAGE",
    	"autoComplete":true,
    	"status":"SENT"
}

------WebKitFormBoundary1bNO60n7FqP5WO4t--

For a complete description of each field, take a look at the JSON Properties section below.

Response Payload

{
    "id": "9sKhW-h-qS9m6Ho3zRv3n2a-rkI="
}

What it looks like

After running your code, the package is created with the appropriate fields for each signer. This is what Signer1 will see:

formFieldPDFPackageSignerView

As you see, the required fields are highlighted for the user to fill out. The Name field will be filled in automatically by OneSpan Sign when the signing is complete.

Likewise, the preparer sees this:

formFieldPDFPackagePreparerView

Get the Code

JSON Properties

Property Type Editable Required Default Sample Value(s)
status string Yes No DRAFT DRAFT / SENT / COMPLETED / ARCHIVED / DECLINED / OPTED_OUT / EXPIRED
autoComplete boolean Yes No true true / false
type string Yes No PACKAGE PACKAGE / TEMPLATE / LAYOUT
name string Yes Yes n/a Test Document Extraction
documents
name string Yes No n/a testDocumentExtraction
extract boolean Yes No false true / false
roles
id string Yes No n/a Preparer1
name string Yes No n/a Sender
type string Yes No SIGNER SIGNER / SENDER
signers
email string Yes Yes n/a preparer.email@example.com
firstName string Yes Yes n/a Michael
lastName string Yes Yes n/a Williams
phone string Yes No n/a 514-555-8888
id string Yes No n/a Preparer1
delivery
email boolean Yes No false true / false
provider boolean Yes No false true / false
download boolean Yes No false true / false