Building a full-featured PDF template
In this tutorial, we will show you how to build a full-featured PDF template and generate a document from it using the Inkit API. Be sure to understand how to create a PDF template and how to generate documents from the Inkit API before you start.
First, download an I-9 form from the US Internal Revenue Service, which we will use as the basis of the template.
Next, create a PDF template by doing the following:
-
In the Inkit web app, select Templates in the left sidebar and then click + Create.
-
In the Create Template page, select PDF from the File Type dropdown box. Then enter I-9 in the Template Name field and an optional description of the template in the Description field. Finally, click Click or Drag a File to Area to Upload and select the i-9-paper-version.pdf that you previously downloaded from the IRS.
Then click Next.
-
In the PDF Editor, click Add Merge Field.
Add all the merge fields and drag them where you want them. You can resize a field by dragging one of the four corners of it. Then click Continue.
-
Save the template by clicking Save.
-
Edit the template. Then, in the Destinations panel, click + Add.
In the Add Destination dialog box, select DocuSign and click Continue.
-
In the DocuSign Settings page, select the Delivery Order of the signatures and click PDF Editor.
-
In the PDF Editor, click the DocuSign Fields tab and then click Add DocuSign Field.
In the Add DocuSign Field dialog box, choose the number of signers in the Signer Number spin box, select the DocuSign field type from the Field Type dropdown box and click Generate Tag. Then click Continue.
Drag the DocuSign field to where you want it. You can resize it by dragging one of the four corners of it. Then click Continue.
-
In the DocuSign Settings page, click Apply.
-
Finally, save the template by clicking Save.
-
Next, write and execute a script in either Python or Node.js, which creates merge parameters for the template that we created from a set of data and generates a PDF document from it:
# Import the Inkit Python package
import inkit
from inkit.exceptions import InkitResponseException
# Import json package
import json
# Replace the string below with your API key
inkit.api_token = "ENTER YOUR API KEY"
try:
# Create a PDF document from a template
resp = inkit.Render.create(
# Specify the ID of the template
template_id = "ENTER YOUR TEMPLATE ID",
# Specify the data for the merge
merge_parameters = {"Last": "Doe", "First": "John", "Middle": "X", "Address": "1234 Main St.", "Apt": "#1", "City": "New York", "State": "NY", "Zip": "10001", "Birth": "01/01/1980", "SSN": "123-45-6789", "Email": "[email protected]", "Phone": "(555) 555-5555", "Citizen": "X",},
# Specify the name of the PDF file
destinations = {"inkit_storage": {"name": "John Doe I-9"}, "docusign": {"signers": {"1": {"name": "John Doe", "email": "[email protected]"}}}}
)
# Print the JSON repsonse of the API call
print(json.dumps(resp.data, indent = 3))
except InkitResponseException as err:
# Print any error
print(err.response.data)
// Import the Inkit Node.js package
const Inkit = require("inkit");
// Replace the string below with your API key
Inkit.apiToken = "ENTER YOUR API KEY";
// Call the PDF renderer
createRender();
// Create a PDF document from a template
async function createRender() {
try {
const result = await Inkit.Render.create({
// Specify the ID of the template
templateId: 'ENTER YOUR TEMPLATE ID',
// Specify the data for the Name field
mergeParameters:
{"Last": "Doe", "First": "John", "Middle": "X", "Address": "1234 Main St.", "Apt": "#1", "City": "New York", "State": "NY", "Zip": "10001", "Birth": "01/01/1980", "SSN": "123-45-6789", "Email": "[email protected]", "Phone": "(555) 555-5555", "Citizen": "X",},
// Specify the name of the PDF file
destinations: {"inkit_storage": {"name": "John Doe I-9"}, "docusign": {"signers": {"1": {"name": "John Doe", "email": "[email protected]"}}}}
});
// Print the JSON response of the API call
console.log(JSON.stringify(result.data, null, 3));
} catch (error) {
// Print any error
console.error(error.response.status, error.response.statusText);
}
}
When viewing the generated document in the Inkit web app, you should see something like this:
Updated 11 days ago