I’m using pdf2json (https://github.com/modesty/pdf2json) to convert some PDF files to JSON. I am modifying the JSON files (the ones generated by pdf2json) and then I would like to obtain the corresponding PDF files using the modified JSON files. Is there a way to achieve this?
Thanks in advance.
2
Answers
A quick look at that page suggests that pdf2json does not export enough information to round-trip back to PDF – it just extracts a useful subset of the PDF.
To round-trip, you can use
cpdf -output-json in.pdf -o out.json
Then modify the JSON file and use:
cpdf -j out.json -o out.pdf
If you want to also edit the page content, you will need
cpdf -output-json -output-json-parse-content-streams -o out.json
instead of the first command.
As described by JohnWhitington the best JSon round trip for edits is probably cpdf as that is its aim in that area.
An alternative for generating from scratch or GO is http://pdfcpu.io/create/create. hence if you parse some existing textual source like JSon out from any app, into compatible input format you can build a fresh complex PDF with that simplistic source.