PDF Fill Form (pdf-fill-form) is Node.js native C++ library for filling PDF forms. Created PDF file is returned back as Node.js Buffer object for further processing or saving - whole process is done in memory. Library offers methods to return filled PDF also as PDF file where pages are converted to images.
Libary uses internally Poppler QT5 for PDF form reading and filling. Cairo is used for PDF creation from page images (when parameter { "save": "imgpdf" } is used).
-
NEW version 3.0.0: Updated QT library to version 5 (by Rob Davarnia @robdvr).
-
Version 2.0.0__: Updated nan library to version 2.4.0. Now pdf-fill-form works also with all latest node.js versions. Tested using 0.12.0, v4.4.7, v5.2.0, v6.3.0, v6.8.0, v6.9.1
-
Supports reading and writing the following PDF form field types: TextField, Checkbox, Radio button
-
You can write following files:
- PDF where pages are converted to images
-
All the work is done in memory - no temporary files created
-
Results are returned in Node.js Buffer -object
-
Not using the PDFtk -executable - instead we use the Poppler library
var pdfFillForm = require('pdf-fill-form');
pdfFillForm.read('test.pdf')
.then(function(result) {
console.log(result);
}, function(err) {
console.log(err);
});
var pdfFillForm = require('pdf-fill-form');
var fs = require('fs');
pdfFillForm.write('test.pdf', { "myField": "myField fill value" }, { "save": "pdf" } )
.then(function(result) {
fs.writeFile("test123.pdf", result, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
}, function(err) {
console.log(err);
});
To read all form fields:
var pdfFillForm = require('pdf-fill-form');
var pdfFields = pdfFillForm.readSync('test.pdf');
console.log(pdfFields);
To write form fields (synchronous) to PDF:
var pdfFillForm = require('pdf-fill-form');
var fs = require('fs');
// Use here the field names you got from read
var pdf = pdfFillForm.writeSync('test.pdf',
{ "myField": "myField fill value" }, { "save": "pdf" } );
fs.writeFileSync('filled_test.pdf', pdf);
To write form fields (aynchronous) to PDF:
var pdfFillForm = require('pdf-fill-form');
var fs = require('fs');
// Use here the field names you got from read
pdfFillForm.writeAsync('test.pdf',
{ "myField": "myField fill value" }, { "save": "pdf" },
function(err, pdf) {
fs.writeFile("filled_test.pdf", pdf, function(err){});
}
);
To write form fields to PDF where pages are converted to images:
Use parameter { "save": "imgpdf" }
Just set the radio button field Value to the caption of the item you want to select.
For example if you have a radio button for gender called "Gender1" with options captioned as "Male" or "Female" then passing in the field {"Gender1": "Male"} will select the male radio button, as expected.