npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pdftk-fill-pdf-options

v2.0.6

Published

fill pdf forms with supplied data

Downloads

13

Readme

pdftk-fill-pdf

PDFtk is required

  • fills multiple form fields using same acrofield name ✔️
  • handles checkboxes ✔️
  • handles undefined and null values with empty string ✔️
  • all asynchronous ✔️
  • returns Buffer ✔️
  • lightweight and no dependencies ✔️
  • exposes pdftk and xfdf for customization ✔️
  • written in typescript ✔️

Install

npm i pdftk-fill-pdf

Examples

basic usage

// commonJS
const pdfFill = require('pdftk-fill-pdf').default;
// ES6 modules
import pdfFill from 'pdftk-fill-pdf';

// key is fieldname in PDF
const fillData = {
  test1: 'abcdefghchijklmnopqrstuvwxyz123456',
  test2: 'another text',
  test_number: 123456789,
  test_special_chars:
    'ěščřžýáíéúůťńóú жжжююю ć, ń, ó, ś, ź Ä/ä, Ö/ö, Ü/ü  /{}"?>:{',
  test_checkbox: true,
  test_radio: true,
  test_null: null,
  test_undefined: undefined,
};

// your code
try {
  const pdfBuffer = await pdfFill.fill({
    pdfPath: 'test/test.pdf',
    data: fillData,
    // optional, temporary file path root
    // tempPath: '/tmp',
  });

  // do with buffer whatever you want i.e. write it into file
  fs.writeFileSync('./test/test_result.pdf', pdfBuffer, { encoding: 'utf8' });
} catch (err) {
  console.error(err);
}

Generate xfdf

const fillData = {
  test1: 'abcdefghchijklmnopqrstuvwxyz123456',
  test2: 'another text',
  test_number: 123456789,
};

try {
  const xfdfString = await pdfFill.generateXfdf({
    pdfPath: 'test/test.pdf', // used for correct Xfdf href
    data: fillData, // same data as above,
    // tempPath: '/tmp', // optional, temporary file path root
  });

  console.log(xfdfString);
} catch (err) {
  console.error(err);
}

Your own pdftk execution

docs: pdftk the pdf toolkit

try {
  // ...
  // node.js exec options
  const OPTIONS = {
    timeout: 100000,
    maxBuffer: 200 * 1024,
  };
  const cmd = `fill_form ${xfdfFile} output ${generatedPdfFile} need_appearances`;
  const stdout = await pdfFill.execPdftk(cmd, OPTIONS);
} catch (err) {
  console.log(err);
}