This Is DOOM and Tetris Inside A PDF Document


You might think of PDFs as static documents, intended for just words, pictures, and occasionally forms. However, modern browsers can unlock more features for PDF documents, as proven by new ports of Tetris and DOOM.



Thomas Rinsma, a security analysist and developer, published a working demonstration of the classic puzzle game Tetris running entirely in a PDF. It’s playable in Google Chrome and other browsers based on Chromium, as well as Mozilla Firefox. You can try it out with the PDF file on Rinsma’s website.


Screenshot of Tetris in a PDF

The blog post explains, “It is relatively well-known that PDFs can be quite feature-rich when opened in Adobe Acrobat/Reader, with scripting support for forms and other dynamic content. However, it turns out that both PDFium (Chromium’s PDF reader) and PDF.js (Firefox’s) implement a little bit of scripting support as well. […] PDFs can contain text input fields, buttons, checkboxes, etcetera. JavaScript handlers can be tied to events on those widgets (“fields”), and properties of these fields can be modified from within JavaScript.”

Essentially, scripting functions intended for checking the content of forms can be repurposed to modify the contents of the PDF. The document creates a grid of buttons that can be programmatically shown or hidden, acting as pixels. The game is controlled through clickable buttons, or keyboard keys typed into a text field.


Rinsma then took this concept a step further, completing a port of the 1993 first-person shooter game DOOM to a PDF. It’s based on the DOOM-ASCII project, a functional version of DOOM playable in text-only environments with ASCII characters, compiled for web browsers using WebAssembly and Emscripten. You can try out DoomPDF in your web browser—this one only works with Chrome and Chromium-based browsers right now.

Screenshot of DoomPDF in Google Chrome.

The DOOM port is definitely slow in Chrome 134 on my M1 Mac Mini, but it does work. The blog post mentions that the game display is monochrome, not in color like the original DOOM-ASCII project, because the color of the button ‘pixels’ can’t be updated without swapping them for other elements. Rinsma explained, “Even for say a GameBoy screen (160x144x3) this is almost 70K fields, which slows things down way too much.”


The source code for PDF Tetris and DoomPDF are available on GitHub. This will go perfectly with the recent DOOM II port on a pinball machine.

Source: Thomas Rinsma



Source link