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

Show all comments

Showing thread 75 of 81

bowmessage1 reply#
Adobe Acrobat DOOM Pro™
mati3651 reply#
What about running Adobe Acrobat in Adobe Acrobat?
andrea762 replies#
Can we run Windows 3.1 in protected mode from a PDF?
mati365#
Imho, it's possible. Generally speaking, it depends if PDF can render any sort of canvas.
danudey1 reply#
Can we compile qemu to a PDF?

Continue this thread — 1 reply

lxgr1 reply#
That's how it inevitably goes with Turing completeness :)

The real achievement here arguably isn't running code (that's provided by the PDF spec and implementations), but managing to hook it up to user input/output in an ergonomic-enough way to play Tetris.

lxgr#
Amazing, thank you!

The PDF [1] containing the Lambda calculus term manages to hang/glitch/crash both Firefox's and macOS Preview's PDF renderer, which in itself is quite the achievement in portability.
Update: Nevermind, Firefox handles it perfectly, it just (probably wisely) disables seamless scrolling and I have to use the "next/previous" page buttons manually. macOS got there after a minute or two of loading with no UI indications.
[1] https://woodrush.github.io/lambda-8cc.pdf

openrisk#
But will it also compile when printed out on paper?