Close

PDF decoding in javascript

A project log for Synchronize a PDF with a spreadsheset

PDFMerge

lion-mclionheadlion mclionhead 10/13/2023 at 05:072 Comments

Lions traditionally used ghostscript to convert a PDF to images.  It's now considered pretty germane.  For a pure browser program, the internet recommends PDF.js

https://github.com/mozilla/pdf.js

A few chatgpt prompts can create a quick demo of how to draw text on a PDF.  For editing, you want the PDF in a persistent canvas & all the text in another canvas, with the 2 composited in 1 step.  Then, the user can alter a text element without redrawing the PDF & every other text element.

The next trick was reading a goog sheet.  There's a diabolical process to get a service account key.  Then a GPT demo using curl was a fail.  GPT can generate another solution using node.js.  They generally involve many steps to create an API key & download an access token.  Helas, the GPT says accessing a goog sheet directly from a web app requires making the sheet public.

At best, it would require hard coding the service account key in the javascript or a javascript include, but if curl can supposedly access it, a very simple web server on another port could just do spreadsheet queries with its own copy of the service account key.  Any solution is going to require a simple python webserver in that case.

The glaring problem is any insertion or deletion in the spreadsheet won't be reflected in the PDF overlay.  It's almost easier to make a spreadsheet program from scratch.  There are so many javascript spreadsheet programs, it might be a favorite toy problem of programmers.  Helas, they vary in features & bugs. 

Discussions

mtalbotaa wrote 03/14/2024 at 09:30 point

Processing PDF files in the browser using JavaScript is quite an interesting topic. Thank you for the informative post. I'd also like to share a great online service that recently helped me a lot when working with text files. With the help of https://pdfguru.com/split-pdf I easily and without any hassle split the PDF file into several separate ones. It was very convenient and took very little time. Also, I want to note that this PDF maker works online on all platforms and doesn't require any additional setup, so feel free to use it, I think it will be useful to many.

  Are you sure? yes | no

opera2390 wrote 01/05/2024 at 16:09 point

Thanks for sharing!

  Are you sure? yes | no