Tetris packed inside a PDF file to run in any PC browser — Pdftris runs from a 60KB PDF

Enjoying some Pdftris
(Image credit: Future)

The classic Tetris game has been packaged into a PDF and dubbed Pdftris. The classic falling blocks puzzler is claimed to be playable in most desktop browsers and, indeed, we successfully loaded and played the game in Firefox on PC simply by clicking the above link. A security analyst named Thomas Rinsma is the brains behind this new PDF-based browser game.

Background details on the project aren't extensive, as the GitHub project page ReadMe entry is empty. However, Rinsma was happy to chat with users on the Hacker News feed about the development project.

Rinsma indicates that he was inspired to port a game to run in a PDF after he "realized that the PDF engines of modern desktop browsers (PDFium and PDF.js) support Javascript with enough I/O primitives to make a basic game like Tetris."

The security analyst and self-confessed aficionado of "strange loops and weird machines" also explained that it wasn't that easy to get his Tetris game to run correctly in both engines. However, he discovered that "showing/hiding annotation 'fields' works well to make monochrome pixels." Moreover, if you try the game with the on-screen buttons and would prefer to use keys, then Rinsma made it so that keyboard control can be achieved by typing in a text input box below the game area.

Rinsma humbly admits that his Tetris in PDF code is "quite janky." However, he suggests it at least serves as a reminder of the power and flexibility of PDF scripting.

(Image credit: Future)

Those interested in prying inside the Pdftris code don't need specialist or esoteric development tools. Just choose to download the 60KB PDF, and open it in a text editor and you will find the file is "all AsCII."

There is some source code available, too, with greater readability and comments inserted. You can see that on the aforementioned GitHub project page, specifically here.

Rinsma noted that Pdftris isn't working on Adobe's Reader "likely because it's not compliant in several ways." Other non-browser Pdftris possibilities like Foxit Reader might work, he mused, as he believes it supports the necessary scripting for the gaming action.

It would be great to get some color, shading, and sound in a future release of Pdftris but we don't know if this project will be developed much further. In some ways, it is basically a proof of concept.

While Pdftris is certainly an eyebrow-raising mashup of the gaming and document rendering worlds, developers have dragged far duller apps into the gaming realm, particularly Microsoft Excel. Microsoft's spreadsheet can even host a 3D raytracing gaming engine (with the help of VBA).

Mark Tyson
News Editor

Mark Tyson is a news editor at Tom's Hardware. He enjoys covering the full breadth of PC tech; from business and semiconductor design to products approaching the edge of reason.

  • ezst036
    Here comes PDFDoom.
    Reply
  • pjmelect
    Dosn't work for me what am I doing wrong I am using Firefox:(
    Reply
  • bit_user
    PDF used to be a nice format, back when it was purely static. It basically took the imaging model of Postscript and left behind all the procedural stuff (which was based on the Forth language, BTW). It was a shame that they couldn't resist adding scripting back into the format.
    Reply