Generate pixel perfect PDF forms with PDFtk and Node.js

Written by
Last updated on:
October 29, 2026

A recent project at FullStack Labs needed PDF forms to be populated dynamically with requested data from a database. Previous projects required generating basic PDF documents with HTML and CSS, but this project required the forms to be pixel-perfect.

The nature of the project called for a large number of these forms to be generated, which we determined would be a costly endeavor if each form was generated with HTML and CSS.

After some research, my team discovered that this process can be streamlined significantly by creating a fillable PDF template and then programmatically filling in each field when the form is requested.

We hoped to find a pure JavaScript solution for our Node.js app, but the packages we found at the time were poorly documented and difficult to use. Instead, we found PDFtk to be the easiest way to populate fillable PDFs, which provides a CLI for reading and writing to PDF form fields. We also used the node-pdftk package which provides a Node.js wrapper for PDFtk.

This article will guide you through the process of bringing the tools and ideas above together in a Node.js application, but the same ideas can be applied to other languages that have their own PDFtk wrappers.

Create a fillable PDF template

The first step is to create a PDF template with fillable form fields. This can be accomplished using Adobe Acrobat Reader DC and the Prepare Form feature. 

The advantage of this approach is that it provides non-technical users the ability to create fillable PDF forms on their own which is typically a more economic solution for clients (especially if numerous forms need to be created and maintained). The Prepare Form feature does require a premium subscription to Adobe Acrobat Reader DC, but the cost is negligible compared to the savings on the development side.

When the fillable form is created, a name is assigned to each field that can later be targeted programmatically by a developer with PDFtk.

For the purposes of this article, you can download the 1099-NEC form from the IRS’s website, which contains fillable form fields.

pixel-perfect PDF form

Identify the PDF form fields to populate

When a developer receives a fillable PDF form, PDFtk reads the PDF and identifies the field names that can be populated. 

To get started, install pdftk locally with Homebrew.

Then, verify that the installation was successful and that the pdftk command is available.

Now, run the dump_data_fields command on the 1099-NEC form you downloaded in the previous section to retrieve data for the available form fields.

The main information that you need from this output is the FieldName, which tells you how to target the form fields programmatically in your code. 

You’ll notice that most of the FieldNames on this form are a bit cryptic, like topmostSubform[0].CopyB[0].CopyBHeader[0].LeftCol[0].f2_1[0], so it might take some trial and error to figure out the actual fields the FieldNames correspond to. If desired, you can also use the Prepare Form feature in Adobe Acrobat Reader DC to inspect or edit the FieldNames so they are more intuitive for development purposes.

Fill out the PDF fields programmatically

1.  Add node-pdftk to your project.

2. Create a file called generate1099Form.js, and import node-pdftk.

3. Add example payer and contractor objects with relevant data. This can be enhanced later to dynamically load the information from a database.

4. Create a fieldMap object that maps the fields from your payer and contractor objects to the FieldName values for the PDF form.

The 1099-NEC PDF has multiple pages with form fields, but in this example, we are just targeting form fields in the Copy B page. As I noted above, you can use the Prepare Form feature in Adobe Acrobat Reader DC to edit the FieldNames so they are more intuitive for development purposes.

5. Now that you have a fieldMap for the form, you just need to pass it to node-pdftk which will generate a new PDF with the corresponding form fields filled out.

6. You can use a framework like Koa or Express to render the pdfBuffer in the browser as a PDF. Here is a streamlined example of what this looks like in Koa:

Congratulations! The final result is a pixel-perfect PDF form!

pixel-perfect PDF form

At FullStack, we understand that building efficient, scalable solutions and creating pixel-perfect PDF forms with tools like PDFtk and Node.js requires not only the right technology but also the right talent. Whether you're looking for skilled engineers to augment your team or need end-to-end project consulting, our experts are ready to help you bring your ideas to life. Partner with us for solutions tailored to your unique business needs. Contact us today to find out how FullStack can support your next initiative.

Frequently asked questions

For this project, we needed to create PDF forms that were pixel-perfect while also dynamically filling them with data from a database. Using HTML and CSS to generate each document would have been too costly and time-consuming. Instead, we used fillable PDF templates combined with PDFtk and Node.js to efficiently produce high-quality, ready-to-use forms at scale.

Fillable PDF templates allow you to design a form once and programmatically populate its fields later. Tools like Adobe Acrobat Reader DC’s Prepare Form feature make this possible, even for non-technical users. Each field is given a name, which developers can target when filling out the form with data. This approach is far more efficient than creating separate PDFs for every form, especially when generating documents in bulk.

PDFtk is a command-line tool for reading and writing PDF form fields. In Node.js, the node-pdftk package provides a lightweight wrapper for working with it. The process involves:

  1. Creating a fillable PDF template with defined field names.
  2. Using PDFtk to identify those fields programmatically.
  3. Passing the correct data into those fields to produce a completed PDF.
    Because PDFtk handles all the rendering, it ensures every generated PDF is pixel-perfect and consistent with your template.

Once you know the field names within your template, you map each one to values in your application—such as payer details, contractor information, or custom data from your database. That mapping is passed to node-pdftk, which fills the fields and returns a complete, locked PDF. From there, you can deliver the document to users, store it securely, or integrate it into automated workflows.

This approach combines PDFtk’s reliable rendering engine with Node.js’s flexibility for fetching and managing data. It’s ideal for businesses that generate large volumes of PDF forms because it:

  • Produces pixel-perfect, compliant documents
  • Reduces development time and manual effort
  • Supports automation for high-volume scenarios
  • Delivers consistent results with every generated form