Code Monkey home page Code Monkey logo

pdf-fill-form's Introduction


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).

Features

  • NEW version 4.0.0: Added feature allowing for parallelization of the imgpdf feature, also allows for settings scale and whether antialiasing should be used (by Albert Astals Cid @tsdgeos).

  • 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
    • 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

Examples

Using promises

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", 'cores': 4, 'scale': 0.2, 'antialias': true } )
.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);
});

Using callbacks

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" }

Notes about using radio buttons (@mttchrry)

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.

Installation

OS X

Preferable method to install library dependencies is via Homebrew

$ brew install qt5 cairo poppler --with-qt5

After dependencies are successfully installed, you can install the library:

$ npm install pdf-fill-form

Homebrew users who get error regarding xcb-shm
The fix is to add this to your bash profile / environment: export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig

If you still run into issues, or had an existing qt installed try to force link it:

brew linkapps qt5
brew link --force qt5

Linux - Ubuntu (trusty)

$ sudo apt-get install libpoppler-qt5-dev libcairo2-dev
$ npm install pdf-fill-form

Linux - Debian (jessie)

To be sure to have the required packages, re-synchronize the package index files from their sources :

$ sudo apt-get update

Then install packages :

$ sudo apt-get install libcairo2-dev libpoppler-qt5-dev 
$ npm install pdf-fill-form

I mostly recommand to install this package to have better support with fonts :

$ sudo apt-get install poppler-data

Todo

  • Tests
  • Refactoring
  • Support for other form field types than CheckBox, Radio button and TextField

Changelog (from 24.5.2017 ->)

v3.2.0 (24.5.2017)

  • Support for radio buttons (by Matt Cherry @mttchrry)

v3.3.0 (14.12.2017)

  • #49 Set radio button "value" to the poppler button state (by Mihai Saru @MitzaCoder)

v4.0.0 (14.12.2017)

  • #45 Set radio button "value" to the poppler button state (by Albert Astals Cid @tsdgeos)

Authors

Contibutors

  • Ethan Goldblum
  • Tyler Iguchi
  • Rob Davarnia
  • Fabrice Ongenae
  • Juwan Yoo
  • Andreas Gruenbacher
  • Andrei Dracea
  • Emil Sedgh
  • Matt Cherry
  • Mario Ferreira
  • Mihai Saru @MitzaCoder
  • Albert Astals Cid @tsdgeos

License

MIT

NOTE ABOUT LIBRARY DEPENDENCIES!
Poppler has GPL license. Cairo has LGPL.

pdf-fill-form's People

Contributors

tpisto avatar tsdgeos avatar emilsedgh avatar egoldblum avatar robdvr avatar mttchrry avatar andreas-gruenbacher avatar vhain avatar ztrange avatar mitzacoder avatar tyleriguchi avatar

Watchers

James Drew avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.