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
illegalmemory2 replies#
Not only web but majorly all OS pdf renderers support JS. It used to be a major source of malware long back.
autoexec#
PDFs are still used to delver malware. Adobe gets picked on less often now since everyone has PDF readers in the browser but that just makes chrome the new target of choice (not that alternative viewers don't get attention too https://thehackernews.com/2024/05/foxit-pdf-reader-flaw-expl...) but what I see most often in malicious PDF files recently are just links to websites that contain malware since they can work no matter what your viewer is.
ykonstant#
"used to be"
toddm#
This is really cool and fun!

I don't know much about the security issues others have raised, but if you're good enough to make this thing then I deserve to be pwned by you.
Chapeau!

frizlab2 replies#
Fortunately this does not work in Safari where the rendering is done natively.
anothername121 reply#
Does not even seem to be a valid PDF according to Preview.app
swiftcoder#
Preview implements a subset of the full capabilities of PDF, and in particular it does not implement the javascript interpreter.
p0w3n3d#
I like how you used "fortunately". For me too the most important in PDF is to print a good and accurate text and graphics (preferably vector graphics), which recently is not as easy as it would be possible
GaggiX#
Kinda happy that Evince doesn't start executing JS when opening a PDF.

Load more comments