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
UniverseHacker5 replies#
This is horrifying, PDFs should not be able to execute code.
cess112 replies#
One should reject all PDF:s except /a-standards compliant ones.
belval1 reply#
Maybe if one enjoys endless conversations with unhappy customers. Easier to simply isolate the PDF rendering/parsing and move on.
silon42#
A conversion tool would be useful.
martin_a1 reply#
Let me tell you about the lord and savior of the printing industry, the PDF/X standard...
cess11#
It allows external sources. I think even the ICC profile can sit outside the document, as well as stuff like video.

I like the archivable series, the document comes with what is needed to render it.

nejsjsjsbsb#
HTMLs too :)
crazygringo#
Seriously, I hate it.

I understand why it happened -- it made sense to allow PDF's to be used for form-filling, and once you can fill in forms it obviously makes sense to validate inputs, and to handle arbitrary validation complexity you need a scripting language, and obviously then you want to be able to automatically fill in fields based on other fields, or even produce a QR code so it can be printed and scanned... And they didn't want to create a new extension like ".ipdf" for interactive PDF.
But still. I hate it.

fsckboy1 reply#
>PDFs should not be able to execute code

Postscript is code (it's a stack machine), and PDFs are Postscript

martin_a#
> PDFs are Postscript

PDFs have moved to native generation, due to the feature richness that has found its way into the specs.
Nevertheless you can still write PS and feed it into a Distiller (or sth. alike) and render the output.

tbraydn1 reply#
A surprising number of things used to accept executable code.

In Microsoft Windows (~2000/ME), you used to be able embed JavaScript and ActiveX into ANY folder by replacing the folder view with your own HTML. Your customization would persist on shared network folders so others would see your HTML.
So naturally, a bunch of us 14 year olds in like 2002, between playing Runescape and Neopets in computer lab and library time, found this out and started screwing with the shared network Z: drive used by both teachers and students across every elementary, middle and high school in the school district.
There were dumb things you could do with all that power like open people’s CD-ROM reader trays by abusing the Windows Media ActiveX control. It had an eject() method on the object.
It ended up breaking in an edit war of the shared drive. There were some generic AD accounts used district-wide so you could avoid getting caught. We found out you could prefix the username with the domain and login with accounts from other schools. At one point, someone crossed the line, but I don’t think anyone got caught.

ta12431 reply#
You put the in right? Or had that been fixed by the DHTML era
slig#
I used to place that as the home page of IE.
chaps1 reply#
They also support iframes! The absolute madness of PDFs is a world wonder. But I'm really still not sure we could do without them.
bityard2 replies#
Gzipped PostScript documents were fairly popular during the 90's and are functionally identical to PDFs for 99% of use cases. (PDF is essentially PostScript, but with more features.)
necovek#
Well, both a simpler language more geared toward presentation, but also including more modern features designed for on-screen viewing.
kccqzy#
For Gzipped PostScript, code execution is its raison d'être. But it is at least possible to build a PDF viewer without code execution.
seany#
This is great. Will probably give the fun police in r/k12sysadmin a heart attack.
Uptrenda#
Actually works, a bit buggy but its a good POC.

Load more comments