A node module to fill out PDF forms (utf8 compatible).
It uses pdftk to fill out PDF forms.
npm install fill-pdf
You need to have the pdftk
binary in your PATH.
- To install PDFtk use the official installer or if you have homebrew-cask installed you can run
brew cask install pdftk
sudo apt-get install pdftk
const fillPdf = require("fill-pdf");
const formData = { FieldName: 'Text to put into form field' };
const pdfTemplatePath = "templates.pdf";
app.get('/filled_form.pdf', (req, res) => {
fillPdf.generatePdf(formData, pdfTemplatePath, function(err, output) {
if ( !err ) {
res.type("application/pdf");
res.send(output);
}
});
});
For more specific uses, you can also pass some extra arguments to pdftk
. It is done by
specifying them as an array, given as a third argument of the fillPdf
function.
For instance, if you want to make the output PDF not editable anymore, you can append the
flatten
argument such as:
const fillPdf = require('fill-pdf');
const extraArgs = ['flatten'];
fillPdf.generatePdf(formData, pdfTemplatePath, extraArgs, (err, output) => {
// ...
});
Take a look on man pdftk
to get a list of all available arguments.
Based on utf8-fdf-generator