A lightweight library that sits between 'pdftk' and jq
.
pdfq
receives via stdin the output of pdftk
's dump_data_fields
command and outputs it as JSON.
If you clone this repo and cd
into the examples
folder, you can run these yourself:
Takes the output from dump_data_fields, pipe it into pdfq, and output json:
pdftk pdfs/SF-52.pdf dump_data_fields | pdfq
Like the previous example, but only outputs fields where FieldType
is Button
.
pdftk pdfs/SF-52.pdf dump_data_fields | pdfq buttons
pdfq
mixes nicely with jq
. In this example, jq filters for fields where FieldType is a Button.
pdftk pdfs/SF-52.pdf dump_data_fields | pdfq | jq '.[] | select(.FieldType=="Button")'
Generates FDF from JSON:
cat json/SF-52-fields.json | pdfq json_to_fdf
Combine the json_to_fdf
command with pdftk
to fill a form from json in two commands:
cat json/SF-52-fields.json | pdfq json_to_fdf > fdfs/SF-52-fields.fdf
pdftk pdfs/SF-52.pdf fill_form fdfs/SF-52-fields.fdf output pdfs/SF-52-filled.pdf
The following commands provide convenience methods on top of pdftk
. To run them, you must have pdftk
on your path.
Gets the value of a single field in the PDF.
pdfq get <field> <pdf_path>
Example:
pdfq get EdLevel pdfs/SF-52-filled.pdf
Sets the value of a single field in the PDF.
pdfq set <field> <value> <input_pdf_path> <output_pdf_path>
Example:
pdfq set EdLevel ED_LEVEL pdfs/SF-52.pdf pdfs/SF-52-filled.pdf
See latest release.
Download the appropriate binary and add it to your path.
Prerequisites:
- Docker
- docker-compose
- mruby-cli
pdfq
is built using mruby
and the mruby-cli
.
The mruby-cli
is used to create the project skeleton and build toolchain.
To modify, run, and test pdfq
, please refer to the mruby-cli
README. However, here's a basic summary:
Right now everything is in mrblib/pdfq.rb
.
$ docker-compose run compile
Then run ./mruby/build/{your build target}/bin/pdfq
version.
Located in test/test_pdfq.rb
.
$ docker-compose run test
Located in bintest/pdfq.rb
.
$ docker-compose run bintest