“An idle brain is the devil’s workshop”
Today marks my first day of mandatory gap period from my work, however it is quite hard to just relax. While sorting files in my laptop, I stumbled upon an old email which required my team to prepare data for an attachment of a report to the presidential office. The attachment was specifically requested in a PDF format. Of course the data itself was already stored in our database connected into a REST API frontend, therefore at that moment I thought there should not be a problem. I assumed that I just need to grab all the JSON result from the API and fed it into some online JSON to PDF converter and voila, 5 minutes work. However, life brought me into a different direction.
Generating the JSON was completed in 1:30 minutes (indeed it was a very very big data) and selecting via sql command was too much trouble, but then I stuck in this state for a while. My google result of “JSON to PDF converter” emerged in two categories a free crappy converter (pdfmall.com, aconvert.com, anyconv.com, etc) or a premium service. It amazed me that why no one made such a decent converter, despite there are many open libraries to do so from python based to go lang. I finished my 901 pages attachment in almost an hour writing a script to dump the result into CSV and save it into PDF via Ms Excel.
This morning I decided to take the challenge. I made not just a decent JSON to PDF converter but also an on-the-fly REST API enabled one. Currently it supports A4 paper in both Portrait and Landscape format, while able to process simple JSON array, object, list of object and geoJSON. It can be used in two approaches, for noobs by using web browser, copy and paste your JSON, put the title and voila. While for IT Wizard that prefers systematic and integrated approach you can use the REST API frontend that returned a PDF file for you. Both approaches will generate you a decent table for your JSON that fits automatically with the paper margins. I tried to run my old JSON data into this system and returned 901 pages of a nicely done PDF document. It is working quite stable (until my last code compilation at least). Please take a look here in json2pdf.fadhlizakiy.com and give me feedback. Happy coding.