Tetris has been crammed into a tiny 60KB PDF, works in any browser

7 hours ago 3

Serving tech enthusiasts for over 25 years.
TechSpot means tech analysis and advice you can trust.

WTF?! A clever security analyst has proven that PDFs are not just for boring documents and forms. He's managed to squeeze the classic Tetris game into a 60KB PDF file that can run right in your browser.

The creation, dubbed "Pdftris" by its maker Thomas Rinsma, lets you play the addictive falling blocks puzzler with just a click. We fired it up on Firefox and sure enough, those tetriminos were tumbling down the makeshift game area like it was 1984 all over again.

For controls, you can use the mouse to click the on-screen buttons, which wasn't intuitive at all. Thankfully, Rinsma also baked in keyboard controls – players can move, rotate, and drop the tetriminos with the WASD keys.

The game has no sound, no color, and is stuck running in a modest browser window. But we'd argue that this adds to the retro charm. And maybe future updates could introduce these missing pieces.

As for how Rinsma managed to cram all this functionality into a file format intended for documents, it's made possible using the rarely-explored realm of PDF scripting, supercharged by none other than JavaScript.

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/YrOInaHOUY

Should work in most browsers (built for pdfium/PDF.js). pic.twitter.com/n4CPcitzz9

– Thomas Rinsma (@thomasrinsma) January 5, 2025

PDF engines that power browsers like Chrome and Firefox actually support a limited set of JavaScript commands. Rinsma realized he could exploit this to cobble together a basic game like Tetris from the ground up.

This wasn't exactly a walk in the park. Rinsma had to figure out hacky workarounds to get his game rendering properly across different PDF engines. His solution was using the show/hide functionality for PDF annotation "fields" to create those iconic monochrome Tetris pixels.

Controlling the action presented another challenge. While you can use the on-screen buttons, Rinsma cleverly enabled keyboard controls by allowing you to type into a text input box below the game. Typing sends keystroke events that the game can interpret into actions.

The result is admittedly pretty "janky" in Rinsma's own words. But that's kind of the beauty of experimental stuff like this.

Under the hood, Pdftris is just plain old ASCII text hiding inside that PDF file. You can download it and open the code in a text editor to see how it works. Or you could check out Rinsma's GitHub repo for some more readable source code with comments.

Now, you might be thinking – if Tetris can run in a PDF, surely someone wouldn't dare try squeezing something crazy like Doom into one too, right? Well, Rinsma knew you'd have that thought. He reckons it could indeed be possible "with the right tricks" if a single PDF engine is targeted.

Read Entire Article