Summary
- This Linux distro runs in a JavaScript-compiled RISC-V emulator within a PDF.
- This PDF file format supports Javascript allowing computation within documents.
- The user input includes a virtual keyboard and a box translating text to on-screen actions.
Every so often, we see a wave of activity around cramming something that shouldn't be running in a specific document or app into said document or app. If you (like myself) had the naive thought that PDF files were static, boring documents that can't do things like, I don't know, play Tetris or something, then boy, do we have news for you. Someone has taken PDF tinkering to the next level and got Linux running within a document, and you can give it a spin if you don't believe me.
Asus ROG Strix B850-F Gaming WiFi review: $300 is a tough pill to swallow
This could have been a solid mid-range AM5 motherboard if it were priced better.
A Linux distro running in a PDF is the wildest thing you'll see today
User vk6_ took to the Linux subreddit to show off their new project. They managed to compile an RISC-V emulator to Javascript and then used it to run Linux within a PDF document.
The technical knowledge needed to get this all working makes my head spin, so I'll instead pass the microphone over to vk6_ who gave an excellent description of what they did and how they did it:
You might expect PDF files to only be comprised of static documents, but surprisingly, the PDF file format supports Javascript with its own separate standard library. Modern browsers (Chromium, Firefox) implement this as part of their PDF engines. However, the APIs that are available in the browser are much more limited. This allows us to do any sort of computation inside the PDF, just with some very limited IO.
C code can be compiled to run within a PDF using an old version of Emscripten that targets asm.js instead of WebAssembly. With this, I can compile a modified version of the TinyEMU RISC-V emulator to asm.js, which can be run within the PDF.
For the user input, vk6_ added a virtual keyboard you can use, and there's a text box that reads what you type in it and translates to actions "on-screen." The output consists of text fields for each row of pixels containing ASCII characters that make up the larger picture. Stunning stuff.
If you want to give the PDF a whirl, check out the Linux PDF document and its source code. And if you like stuff like this, check out someone playing Doom in a Word document.
