Why create a playable version of Tetris within a PDF? 'Why not?'

A playable version of Tetris within a PDF file viewed in the Chrome browser.
You can play a version of Tetris within a PDF file, though you shouldn't expect smooth gameplay. (Image credit: Future)

When you think of PDFs, you probably think about work documents, contracts, and static images. The file format is not known as a gaming platform, but that's exactly how one developer decided to use it. Thomas Rinsma, a security analyst, created a fully functional version of Tetris within a PDF file. While I don't think the game, dubbed pdftris, will become a staple for PC gamers, it is an interesting hacker project that shows the capabilities of PDF files when used in a unique way.

You can play Tetris within a PDF by opening this file in a compatible browser. Rinsma notes that Firefox and all Chromium browsers are supported, though I had a better experience in Chrome than within Edge. That's likely due to the fact that Edge uses Adobe Reader, which is "not compliant in several ways," according to Rinsma.

Sadly for mobile gamers, pdftris only works within desktop browsers at the moment.

The game does not exactly run smoothly, which is hardly a surprise. When I loaded pdftris in Edge the framerate of the game was so low I couldn't play it correctly. The game ran better within Chrome but showed some black lines across my screen. But smooth gameplay isn't what a project like pdftris is about.

Getting Tetris within a PDF was a fun project that also presented a challenge to overcome. Both PDFium, Chromium's PDF reader, and PDF.js, Firefox's PDF reader, use different engines.

"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," explained Rinsma in a post on Hacker News.

Following feedback from users and those interested in the project, Rinsma shared a blog post about the project. There, they answer the first question I imagine many people will ask, "why would you make Tetris within a PDF?" The short answer from Rinsma is "why not?" Inspiration for the project came after Rinsma realized that PDF engines in modern desktop browsers support JavaScript and some I/O primitives.

You can also check out the project on GitHub to see the code used to make keystroke-entry within a text field that allows you to control the following blocks within pdftris.

In case you were wondering, yes, a PDF can be used to run Doom. Rinsma managed to get the classic game working within a PDF after some tinkering.

CATEGORIES
Sean Endicott
News Writer and apps editor

Sean Endicott is a tech journalist at Windows Central, specializing in Windows, Microsoft software, AI, and PCs. He's covered major launches, from Windows 10 and 11 to the rise of AI tools like ChatGPT. Sean's journey began with the Lumia 740, leading to strong ties with app developers. Outside writing, he coaches American football, utilizing Microsoft services to manage his team. He studied broadcast journalism at Nottingham Trent University and is active on X @SeanEndicott_ and Threads @sean_endicott_.