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, enter I-9 in the Template Name field and an optional description of the template in the Description field, and 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, select the first page of the PDF and click Add Merge Field.
Add merge fields and drag them where you want them, or enter their Coordinates. You can resize a field by dragging one of the four corners of it. You also change their font, font size and color.
-
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, or enter the Coordinates for it. You can resize it by dragging one of the four corners of it. To add another field click + Add.
Then click Apply.
-
Save the template by clicking Save.
-
Next, write a script in either Python or Node.js, which creates merge parameters and DocuSign fields for the template that we created from sets 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); } }
Finally, in a terminal or command prompt execute the script by running one of the following commands:
python [script]
(Python)node [script]
(Node.js)
When viewing the generated document in the Inkit web app, you should see something like this:
Updated 7 months ago