jjwilly16 / node-pdftk

A wrapper for PDF Toolkit with streams and promises.
MIT License
139 stars 33 forks source link

Feature/generate json form data #30

Open ocallarob opened 5 years ago

ocallarob commented 5 years ago

Working on a Spike to look at dynamic, automated PDF forms. Felt this feature opens enough functionality, while not intruding too much on the wrapper, to warrant pushing to master.

After generating an fdf, the resolved buffer can be converted to a JSON by calling:

pdftk.fdfToJson(buffer)

This returns a JSON representation of the fdf data:

{ "\T Value1String": "\V Value1String", ... }

Which can be changed programatically and used as a parameter for fillForm later on. This opens up automated form filling. This is a stand-alone static function but I feel it fits well in the pdftk wrapper as it makes it more Node.js friendly.

Note: The implementation is kind of crude, possibly someone with better Regex skills could improve it.

P.S. - This is my first contribution to an Open Source Project, any feedback would be appreciated!

Rob