Earlier, a developer encapsulated the Tetris game into a separate PDF file. It is actually very inaccurate to say that it is encapsulated, because the game was actually developed according to Tetris rules through PDF, rather than encapsulating the existing game into a PDF file.

Now there is a new way to encapsulate the Linux system into a PDF file and run it. The developer vk6_ successfully compiled the RISC-V simulator into JavaScript. The PDF file format supports JavaScript and has its own standard library, so this engine is used to run the Linux system.

Developer vk6_ said in a Reddit forum post:

You might think that PDF files only consist of static files, but surprisingly the PDF file format supports JavaScript and has its own independent standard library, which modern browsers such as Chromium and Firefox implement as part of the PDF engine.

But the API available in the browser is very limited, but being able to do any kind of calculations inside the PDF requires only some very limited IO.

Using the old version of Emscripten (which targets asm.js instead of WebAssembly) to compile C code to run in PDF, we can compile the modified TinyEMURISC-V simulator to asm.js and then run it in PDF.

In terms of input, the developer added a virtual keyboard that can be clicked with the mouse, and also added a text box. When you enter content in the text box, it will be converted into on-screen operations. For example, you can change the password when you press passwd and press Enter in the input box.

The output content is composed of a text field of pixels per line, which contains ASCII characters that form a large image. It has to be said that the developers have really played with the PDF format.

Interested users can check out this project: https://github.com/ading2210/linuxpdf

Sample project: https://linux.doompdf.dev/linux.pdf