Field Injection

This guide shows you how to inject fields on your PDF document with OneSpan Sign.

The field injection feature stamps values directly onto the document during document upload. To enable field injection, you will need a PDF with form fields. In addition, the names of your form fields in your PDF must be the same as the injected field names in your code. Note that currently injecting data into a document, using OneSpan Sign, can only be done when uploading your document and can only be done through the API/SDKs.

The Code

Full code for this guide can be found in the Developer Community Code Share, here.

This guide shows you how to inject text fields as this is probably what you will end up doing. However, you can inject any type of unbound field you like. You can find a complete list of OneSpan Sign’s unbound fields here.

The sample code below shows you how to edit the document block for injecting text fields. The withName() method is where you input the name of your PDF form field you want to inject text to, as it is named in your PDF form. The withValue() method is the text you want to stamp on your document. If you need a comparison to the basic document object creation or if this is your first time creating a package (transaction in the new UI) with the Java SDK, see this guide.

.withDocument(DocumentBuilder.newDocumentWithName("Sample Contract")
		.enableExtraction()
		.fromStream(fs, DocumentType.PDF)
		.withInjectedField(FieldBuilder.textField()
				.withName("Text1")
				.withValue("200 E MAIN ST, PHOENIX AZ, 85123 USA"))
		.withInjectedField(FieldBuilder.textField()
				.withName("Text2")
				.withValue("Lawn mower"))
		.withInjectedField(FieldBuilder.textField()
				.withName("Text3")
				.withValue("Fertilizer"))
		.withInjectedField(FieldBuilder.textField()
				.withName("Text4")
				.withValue("100"))
		.withInjectedField(FieldBuilder.textField()
				.withName("Text5")
				.withValue("12   12   12")))

Running Your Code

The PDF used in this guide can be found here. Once you’ve run your code, if you log into OneSpan Sign, you should find the appropriate text fields stamped in the document in your OneSpan Sign document package, as seen below.

Capture

Get the Code | See this feature in action in our Interactive Demo

The field injection feature stamps values directly onto the document during document upload. To enable field injection, you will need a PDF with form fields. In addition, the names of your form fields in your PDF must be the same as the injected field names in your code. Note that currently injecting data into a document, using OneSpan Sign, can only be done when uploading your document and can only be done through the API/SDKs.

The Code

Full code for this guide can be found in the Developer Community Code Share, here.

This guide shows you how to inject text fields as this is probably what you will end up doing. However, you can inject any type of unbound field you like. You can find a complete list of OneSpan Sign’s unbound fields here.

The sample code below shows you how to edit the document block for injecting text fields. The withName() method is where you input the name of your PDF form field you want to inject text to, as it is named in your PDF form. The withValue() method is the text you want to stamp on your document. If you need a comparison to the basic document object creation or if this is your first time creating a package (transaction in the new UI) with the .NET SDK, see this guide.

.WithDocument(DocumentBuilder.NewDocumentNamed("sample contract")
                .EnableExtraction()
                .FromStream(fs, DocumentType.PDF)
                .WithInjectedField(FieldBuilder.TextField()
                    .WithId("Text1")
                    .WithName("Text1")
                    .WithValue("200 E MAIN ST, PHOENIX AZ, 85123 USA"))
                .WithInjectedField(FieldBuilder.TextField()
                    .WithId("Text2")
                    .WithName("Text2")
                    .WithValue("Lawn mower"))
                .WithInjectedField(FieldBuilder.TextField()
                    .WithId("Text3")
                    .WithName("Text3")
                    .WithValue("Fertilizer"))
                .WithInjectedField(FieldBuilder.TextField()
                    .WithId("Text4")
                    .WithName("Text4")
                    .WithValue("100"))
                .WithInjectedField(FieldBuilder.TextField()
                    .WithId("Text5")
                    .WithName("Text5")
                    .WithValue("12   12   12"))

Running Your Code

The PDF used in this guide can be found here. Once you’ve run your code, if you log into OneSpan Sign, you should find the appropriate text fields stamped in the document in your OneSpan Sign document package, as seen below.

Capture

Get the Code | See this feature in action in our Interactive Demo

The field injection feature stamps values directly onto the document during document upload. To enable field injection, you will need a PDF with form fields. In addition, the names of your form fields in your PDF must be the same as the injected field names in your code. Note that currently injecting data into a document, using OneSpan Sign, can only be done when uploading your document and can only be done through the API/SDKs.

The Code

Full code for this guide can be found in the Developer Community Code Share, here.

This guide shows you how to inject text fields as this is probably what you will end up doing. However, you can inject any type of unbound field you like. You can find a complete list of OneSpan Sign’s unbound fields here.

The sample JSON below shows you how to edit the document object for injecting text fields. In the fields object, the name attribute is where you input the name of your PDF form field you want to inject text to. The value attribute is where you input the text you want to inject on your document. If you need a comparison to the basic document object creation or if this is your first time creating a package (transaction in the new UI) with the REST API, see this guide.

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"

{
  "documents": [
    {
      "fields": [
        {
          "value": "200 E MAIN ST, PHOENIX AZ, 85123 USA",
          "name": "Text1"
        },
        {
          "value": "Lawn mower",
          "name": "Text2"
        },
        {
          "value": "Fertilizer",
          "name": "Text3"
        },
        {
          "value": "100",
          "name": "Text4"
        },
        {
          "value": "12   12   12",
          "name": "Text5"
        }
      ],
      "extract": true,
      "name": "Sample Contract"
    }
  ],
  "type": "PACKAGE",
  "status": "DRAFT",
  "roles": [
    {
      "id": "client",
      "index": 0,
      "type": "SIGNER",
      "signers": [
        {
          "email": "john.smith@example.com",
          "firstName": "John",
          "lastName": "Smith",
          "id": "client"
        }
      ],
      "name": "client"
    },
    {
      "id": "contractor",
      "index": 1,
      "type": "SENDER",
      "signers": [
        {
          "email": "myemail@example.com",
          "firstName": "Haris",
          "lastName": "Haidary",
          "id": "contractor"
        }
      ],
      "name": "contractor"
    }
  ],
  "name": "Field Injection Example"
}

------WebKitFormBoundary1bNO60n7FqP5WO4t--

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

Response Payload

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

Running Your Code

The PDF used in this guide can be found here. Once you’ve run your code, if you log into OneSpan Sign, you should find the appropriate text fields stamped in the document in your OneSpan Sign document package, as seen below.

Capture

Get the Code | See this feature in action in our Interactive Demo

JSON Properties

Property Type Editable Required Default Sample Value(s)
status string Yes No DRAFT DRAFT / SENT / COMPLETED / ARCHIVED / DECLINED / OPTED_OUT / EXPIRED
type string Yes No PACKAGE PACKAGE / TEMPLATE / LAYOUT
name string Yes Yes n/a Field Injection Example
documents
name string Yes No n/a Sample Contract
extract boolean Yes No false false / true
fields
value string Yes No n/a 200 E MAIN ST, PHOENIX AZ, 85123 USA
name string Yes No n/a Text1
roles
id string Yes No n/a Client1
name string Yes No n/a Client1
type string Yes No SIGNER SIGNER / SENDER
signers
email string Yes Yes n/a preparer.email@example.com
firstName string Yes Yes n/a John
lastName string Yes Yes n/a Smith
phone string Yes No n/a 514-555-8888
id string Yes No n/a Client1
company string Yes No n/a Acme Inc.
title string Yes No n/a Managing Director

The field injection feature stamps values directly onto the document during document upload. To enable field injection, you will need a PDF with form fields. In addition, the names of your form fields in your PDF must be the same as the injected field names in your code. Note that currently injecting data into a document, using OneSpan Sign, can only be done when uploading your document and can only be done through the API/SDKs.

The Code

Full code for this guide can be found in the Developer Community Code Share, here.
The sample code below shows you how to build the Document object for injecting text fields. The name attribute of field is where you input the name of your PDF form field you want to inject text to. The value attribute of field is the text you want to stamp on your document.
If you need a comparison to the basic document object creation or if this is your first time creating a package (transaction in the new UI) with the Apex SDK, see this guide.

	String documentId = 'document1'; 
        StaticResource sr = [SELECT Id, Body FROM StaticResource WHERE Name = 'test_field_injection' LIMIT 1];
        Map<String,Blob> doc = new Map<String,Blob>();
        doc.put(documentId, sr.Body);
         
        ESignLiveAPIObjects.Document document = new ESignLiveAPIObjects.Document();
        document.name = documentId;
        document.id = documentId;
        document.extract = true;
        
        //set field injection
        ESignLiveAPIObjects.Field field1 = new ESignLiveAPIObjects.Field();
        field1.name = 'Text1';
        field1.value = '200 E MAIN ST, PHOENIX AZ, 85123 USA';
        
        ESignLiveAPIObjects.Field field2 = new ESignLiveAPIObjects.Field();
        field2.name = 'Text2';
        field2.value = 'Lawn mower';
        
        ESignLiveAPIObjects.Field field3 = new ESignLiveAPIObjects.Field();
        field3.name = 'Text3';
        field3.value = 'Fertilizer';
        
        ESignLiveAPIObjects.Field field4 = new ESignLiveAPIObjects.Field();
        field4.name = 'Text4';
        field4.value = '100';
        
        ESignLiveAPIObjects.Field field5 = new ESignLiveAPIObjects.Field();
        field5.name = 'Text5';
        field5.value = '12   12   12';
        
        document.fields = new List<ESignLiveAPIObjects.Field>{field1,field2,field3,field4,field5};
        
        sdk.createDocuments(packageId, document, doc);

Running Your Code

The PDF used in this guide can be found here. Once you’ve run your code, if you log into OneSpan Sign, you should find the appropriate text fields stamped in the document in your OneSpan Sign document package, as seen below.
Capture
Get the Code | See this feature in action in our Interactive Demo