Tetris packed inside a PDF file to run in any PC browser — Pdftris runs from a 60KB PDF
Game runs in modern browsers using either PDFium.js or PDF.js rendering.
The classic Tetris game has been packaged into a PDF and dubbed Pdftris. The classic falling blocks puzzler is claimed to be playable in most desktop browsers and, indeed, we successfully loaded and played the game in Firefox on PC simply by clicking the above link. A security analyst named Thomas Rinsma is the brains behind this new PDF-based browser game.
Here's a working game of Tetris inside a PDF. Even has keyboard controls (by typing WAsD in an input box). Plus, upon game-over you can "save" your score by printing the page ;)https://t.co/YrOInaHOUYshould work in most browsers (built for pdfium/PDF.js). pic.twitter.com/n4CPcitzz9January 5, 2025
Background details on the project aren't extensive, as the GitHub project page ReadMe entry is empty. However, Rinsma was happy to chat with users on the Hacker News feed about the development project.
Rinsma indicates that he was inspired to port a game to run in a PDF after he "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."
The security analyst and self-confessed aficionado of "strange loops and weird machines" also explained that it wasn't that easy to get his Tetris game to run correctly in both engines. However, he discovered that "showing/hiding annotation 'fields' works well to make monochrome pixels." Moreover, if you try the game with the on-screen buttons and would prefer to use keys, then Rinsma made it so that keyboard control can be achieved by typing in a text input box below the game area.
Rinsma humbly admits that his Tetris in PDF code is "quite janky." However, he suggests it at least serves as a reminder of the power and flexibility of PDF scripting.
Those interested in prying inside the Pdftris code don't need specialist or esoteric development tools. Just choose to download the 60KB PDF, and open it in a text editor and you will find the file is "all AsCII."
There is some source code available, too, with greater readability and comments inserted. You can see that on the aforementioned GitHub project page, specifically here.
stay On the Cutting Edge: Get the Tom's Hardware Newsletter
Get Tom's Hardware's best news and in-depth reviews, straight to your inbox.
Rinsma noted that Pdftris isn't working on Adobe's Reader "likely because it's not compliant in several ways." Other non-browser Pdftris possibilities like Foxit Reader might work, he mused, as he believes it supports the necessary scripting for the gaming action.
It would be great to get some color, shading, and sound in a future release of Pdftris but we don't know if this project will be developed much further. In some ways, it is basically a proof of concept.
While Pdftris is certainly an eyebrow-raising mashup of the gaming and document rendering worlds, developers have dragged far duller apps into the gaming realm, particularly Microsoft Excel. Microsoft's spreadsheet can even host a 3D raytracing gaming engine (with the help of VBA).
Mark Tyson is a news editor at Tom's Hardware. He enjoys covering the full breadth of PC tech; from business and semiconductor design to products approaching the edge of reason.
-
bit_user PDF used to be a nice format, back when it was purely static. It basically took the imaging model of Postscript and left behind all the procedural stuff (which was based on the Forth language, BTW). It was a shame that they couldn't resist adding scripting back into the format.Reply