Lurker News
I realized that the PDF engines of modern desktop browsers (PDFium and PDF.js) support JavaScript with enough I/O primitives to make a basic game like Tetris.

It was a bit tricky to find a union of features that work in both engines, but in the end it turns out that showing/hiding annotation "fields" works well to make monochrome pixels, and keyboard input can be achieved by typing in a text input box.
All in all it's quite janky but a nice reminder of how general purpose PDF scripting can be. The linked PDF is all ASCII so you can just open it in a text editor, or have a look at the source code here: https://github.com/ThomasRinsma/pdftris/blob/main/gengrid.py

Comments (223) 81 threads

Earlier comments
alana3141 reply#
Wow, I had no idea PDFs could be this dynamic. Doesn't work in Mac OS preview or quicklook but works great in chrome.
danudey1 reply#
The Canadian passport application PDF has Javascript that updates a QR code in the top-right corner of the first page whenever you change or fill in a field.

https://www.canada.ca/content/dam/ircc/migration/ircc/englis...
Seems like a pretty genius way of avoiding transcription errors. When I dropped my passport application off yesterday the passport officer marked up a few things on the PDF and then scanned it in, so I assume that they use the QR code to automatically fill in the data as I entered it and then make any updates necessary from after-the-fact modifications manually.
Only seemed to work correctly in Acrobat Reader, but I haven't tried others (like Foxit) or anything.

audiodude#
Yes, elsewhere in this thread people were complaining about how Canadian government PDFs only work in Acrobat Reader on Windows and what a PITA that is.
ninalanyon1 reply#
I'm very pleased that this did not work in Firefox on Linux Mint. Unfortunately it does work in Vivaldi.
skykooler#
It works in Firefox on Manjaro.
enews012 replies#
Wow this was quite fun and impressive! Looks like it doesn't work on Firefox, I wonder why.
jancek27#
Just played it on Firefox. Maybe we have different browser settings?
julian37#
Works fine here (134.0 on macOS)
Shinchy#
That's truly amazing! I knew you could do a lot with PDF but that not to this extent.

Load more comments