Unbelievable: an IT specialist has "uploaded" the legendary game of Tetris to a PDF file, so you can play with any browser

A clever security analyst proved that PDF files are not just for boring documents and forms. He managed to fit the classic game of Tetris into a 60KB PDF file that can be run in any browser.

Unbelievable: an IT specialist has "uploaded" the legendary game of Tetris to a PDF file, so you can play with any browser

"Pdftris is played with mouse or keyboard

Called "Pdftris" by its creator Thomas Rinsma, it allows you to play an addictive puzzle of falling blocks with just one click. 

The game can be controlled with a mouse and on-screen buttons and is not intuitive. 

T. Rinsma has also introduced keyboard control - players can move, rotate and throw tetris blocks using the WASD keys.

The game has no sound, no colours and runs in a modest browser window. Perhaps future updates could introduce these sound and colour elements.

How was Pdftris developed?

It turned out that T. Rinsma was able to fit the game's features into a document file format using the rarely explored area of PDF scripts complemented by JavaScript.

The PDF engines used in browsers such as Chrome and Firefox actually support a limited set of JavaScript commands. Mr Rinsma realised that he could take advantage of this and build a game like Tetris from the ground up.

This was no easy task. Rinsma had to come up with complex ways to make the game render properly in different PDF engines. His solution was to use the display and hide function of the PDF annotation "fields" to create symbolic monochrome pixels for Tetris.

According to the author, Pdftris is rather "lame"

Another challenge is the control of actions. Although on-screen buttons can be used, Rinsma has cleverly incorporated keyboard control, allowing text to be entered in the text input box below the game. Typing sends keystroke events which the game can interpret into actions.

The result is, as Rinsma himself says, rather "lame". But that is the beauty of this kind of experimental stuff.

"Pdftris is just plain old ASCII text hidden in a PDF file. You can download it and open the code in a text editor to see how it works. Alternatively, you can check out T. Rinsma's GitHub repository for more readable source code with comments.

You might think - if Tetris can work in a PDF file, surely nobody would dare try to squeeze something as crazy as Doom into it. Well, Rinsma knew that gamers might have that idea. He thinks it would indeed be possible "with the right tricks" if a single PDF engine were chosen.

User Comments (0)

Add Comment
We'll never share your email with anyone else.
Today: ()