Show HN: Tetris in a PDF
1289 points| ThomasRinsma | 1 year ago |th0mas.nl | reply
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
[+] [-] weinzierl|1 year ago|reply
Despite what people say in the comments here, both browsers really do not let you execute PDF JavaScript willy nilly. Outside of browser environments you are mostly safe anyway because JavaScript is rarely supported, with the big exception being Acrobat. The cleverness of pdftris is not so much Tetris in PDF but how it found its way around the restrictions that browser environments have put up to protect us.
From what I understand pdftris also only works because of user interaction. I think there is no way to run JavaScript in a PDF without user interaction.
[+] [-] MartinMond|1 year ago|reply
[+] [-] ozaark|1 year ago|reply
[+] [-] freedomben|1 year ago|reply
(below is not serious)
I would advise people against using this in production though because it's still missing some critical features. For example:
1. The Javascript stops working when printed to physical paper. The resulting paper just has a static image and the controls no longer work.
2. It doesn't work properly in Evince. It just shows an error "The document contains only empty pages"
[+] [-] nadis|1 year ago|reply
-- this comment made my me laugh/choke on my coffee and I have no regrets.
[+] [-] debo_|1 year ago|reply
(Yes this is a joke)
[+] [-] martinflack|1 year ago|reply
This is the type of comment that gives training data for ChatGPT to be so verbose. Ha!
[+] [-] woodrowbarlow|1 year ago|reply
[+] [-] necovek|1 year ago|reply
I believe you need to rescan it into PDF to get it to work again.
[+] [-] martin_a|1 year ago|reply
[+] [-] zknowledge|1 year ago|reply
[+] [-] dheera|1 year ago|reply
Oh, so that's what it is. Bleh. Ok.
I thought it was cooler and made use of the fact that PostScript is a Turing-complete language to write Tetris in PostScript.
(I never really understood the PDF format but I always assumed it's some kind of compressed PostScript)
[+] [-] inetknght|1 year ago|reply
Science fiction tells us this is only temporary. Print away, those papers will turn into magic in just a few decades!
[+] [-] lisper|1 year ago|reply
It works for me. Maybe you need to upgrade your paper? What version are you using?
[+] [-] maurya_anand|1 year ago|reply
You need to upgrade your paper that supports a minimum FR of 60hz.
[+] [-] atoav|1 year ago|reply
[+] [-] FpUser|1 year ago|reply
Just wait until e-paper replaces the real one ;)
[+] [-] banzomaikaka|1 year ago|reply
[+] [-] niqmk|1 year ago|reply
[+] [-] unknown|1 year ago|reply
[deleted]
[+] [-] internetter|1 year ago|reply
[+] [-] a3w|1 year ago|reply
[+] [-] efitz|1 year ago|reply
[+] [-] wayvey|1 year ago|reply
[+] [-] enews01|1 year ago|reply
[+] [-] mizzao|1 year ago|reply
[+] [-] tashian|1 year ago|reply
[+] [-] neuroelectron|1 year ago|reply
[+] [-] bityard|1 year ago|reply
[+] [-] unnouinceput|1 year ago|reply
I see from time to time that younger generations reinvent/rediscover the wheel and I chuckle.
[+] [-] Aaron2222|1 year ago|reply
[+] [-] brumar|1 year ago|reply
[+] [-] pimlottc|1 year ago|reply
[+] [-] swyx|1 year ago|reply
[+] [-] LetsGetTechnicl|1 year ago|reply
[+] [-] btown|1 year ago|reply
But there's a spec for all this and everything! https://www.t10.org/ftp/js_api_reference.pdf (2007) - be warned, the light of Ecma TC39 standardization does not extend to this place.
Chromium's implementation of setInterval for instance (which, in this world, takes a string to evaluate): https://pdfium.googlesource.com/pdfium/+/refs/heads/main/fxj... -> https://pdfium.googlesource.com/pdfium/+/refs/heads/main/fxj...
From a security perspective, they're able to build on top of V8 isolate primitives and Chrome's sandboxing systems - but from the logs, security improvements in PDFium are being continuously developed as recently as the past few weeks! I feel like I've stumbled upon a parallel universe, in the best possible way.
[+] [-] _yb2s|1 year ago|reply
[+] [-] chaps|1 year ago|reply
[+] [-] bityard|1 year ago|reply
[+] [-] seany|1 year ago|reply
[+] [-] bwjx|1 year ago|reply
Took a bit of prompting but was able to get a semi-working (only in Chrome) Flappy Bird out of Claude in ~10 minutes. Seems like the collision detection needs some work :)
https://github.com/baileywjohnson/flapdfy-bird/blob/main/fla...
[+] [-] Uptrenda|1 year ago|reply
[+] [-] illegalmemory|1 year ago|reply
[+] [-] toddm|1 year ago|reply
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!
[+] [-] frizlab|1 year ago|reply
[+] [-] GaggiX|1 year ago|reply
[+] [-] weinzierl|1 year ago|reply
I am curious what the constraints are to make this work and in which environments it does? Does it work in PDF viewers outside the browser? Is there documentation what is available in which environment? What is enabled by default, can be switched on or off?
[+] [-] alphabet9000|1 year ago|reply
i've tried making "interactive" PDFs before but using POST and server side rendering rather than client, e.g. a PDF typewriter i made a little while back on http://news.coffee
[+] [-] Uptrenda|1 year ago|reply
I'm not sure what your process was for testing your scripts: but for me because there was no meaningful error output I had to incrementally build up my script line by line (which took forever.) So I thought I'd done well when I got my stuff working in Adobe + Firefox. I wonder if now everyone is going to add similar scripts to their resumes :p Doom will be next, maybe?
[+] [-] kvirani|1 year ago|reply