Pdftris is a Tetris game inside a PDF which runs in any modern PC browser

3 days ago 8

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.

Enjoying some Pdftris

(Image credit: Future)

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.

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).

Read Entire Article