Revolutionizing Gaming: Tetris Inside a PDF Document

01/12/2025

In an innovative twist, the iconic block-stacking game Tetris has been ingeniously embedded into a PDF document, christened as Pdftris. This unique browser-based game can be played on most desktop browsers, including Firefox, where it was successfully tested. The creator, security analyst Thomas Rinsma, leveraged the JavaScript capabilities of modern PDF engines to bring this concept to life. Players can control the game using keyboard inputs by typing WASD in a designated input box. Upon finishing a game session, users can even save their scores by printing the page. This development showcases the versatility and potential of PDF scripting.

The inception of Pdftris stems from Rinsma's realization that contemporary PDF engines, such as PDFium and PDF.js, support sufficient JavaScript functionalities to create a basic game like Tetris. Despite the challenges faced during development, Rinsma managed to implement an effective method for rendering monochrome pixels through showing and hiding annotation fields. He also introduced keyboard controls via a text input box below the game area, enhancing user interaction. Although Rinsma admits that the code is somewhat messy, he believes it serves as a testament to the power and flexibility of PDF scripting.

Rinsma's project, while primarily a proof of concept, opens up new possibilities for embedding interactive elements within PDF documents. The source code for Pdftris is accessible and can be explored by downloading the 60KB PDF file and opening it in a text editor. For those interested in a more readable version, the GitHub repository provides commented source code. Notably, Pdftris does not work with Adobe Reader due to non-compliance issues but might function with other PDF readers like Foxit Reader, which supports necessary scripting features.

While Pdftris may not include advanced features like color, shading, or sound, it stands out as a remarkable blend of gaming and document rendering technologies. This creation highlights the potential for transforming mundane applications into engaging platforms, similar to how developers have turned Microsoft Excel into a gaming environment with a 3D raytracing engine. Pdftris exemplifies the creative potential when merging different technological domains, offering a glimpse into what future innovations might hold.