top | item 42678754

Show HN: Doom (1993) in a PDF

369 points| vk6 | 1 year ago |doompdf.pages.dev

I made a Doom source port that runs within a PDF file.

I was inspired by the recent HN post about Tetris in a PDF (https://news.ycombinator.com/item?id=42645218) and I wondered if I could get Doom to run using a similar method.

It turns out that old versions of Emscripten can compile C to asm.js code that will happily run inside the limited JS runtime of the PDF engine. I used the doomgeneric (https://github.com/ozkl/doomgeneric) fork of the original Doom source, as that made writing the IO fairly easy. All I had to do was implement a framebuffer and keyboard inputs.

Unlike previous interactive PDF demos, the output for DoomPDF is achieved by creating a text field for each row of pixels in the screen, then setting their contents to various ASCII characters. This gives me a 6 color monochrome display, that can be updated reasonably quickly (80ms per frame).

The source code is available at: https://github.com/ading2210/doompdf

Note that this PDF can only run in Chromium-based browsers that use the PDFium engine.

74 comments

order
[+] ThomasRinsma|1 year ago|reply
Author of "PDF Tetris" here.

Great work! We had the same idea at the same time, here's my version of PDF Doom:

Source: https://github.com/thomasRinsma/pdfdoom

Playable here: https://th0mas.nl/downloads/doom.pdf

Yours is neater in many ways though!

[+] OnionBlender|1 year ago|reply
"There was a problem with this document". Is the problem me, or the document?
[+] wingi|1 year ago|reply
This is just awesome!
[+] pavo-etc|1 year ago|reply
> limited JS runtime of the PDF engine

humanity has gone too far

[+] miki123211|1 year ago|reply
Seriously though, is there another format that:

1. Can be easily and freely shared by email / cloud drive, including assets, images and fonts.

2. Supports form filling and saving the form data in the file directly (as opposed to sending it somewhere over HTTP). Basically the electronic equivalent of a paper form that can be filled, send by email and stay filled.

3. Supports (cryptographic) signatures that are again part of the document, and can easily and securely be verified by end users. This is a very important use case in the EU, where electronic signatures are based on cryptography, not "I pinky swear I'm John Smith" DocuSign.

4. Has perfect print fidelity.

We keep complaining about PDF (and rightly so), but there's truly no other format to replace it. The W3c / Whatwg / whatever could probably come up with one based on web technologies, but they haven't yet.

There's Epub which solves a very narrow use case of PDF (electronic book distribution where perfect control over presentation is not required), but nothing that solves the "business" use cases.

[+] quotemstr|1 year ago|reply
:-) I'll never quite appreciate why people say things like this. Having some kind of embedded scripting is useful for all sorts of things, often form validation. A sufficiently complex validation system becomes Turing complete, so you might as well skip the hassle of a custom language and go right to JavaScript. Once you have JavaScript, input, and some way of updating a graphical pixel grid, you're at Doom-completeness. I think it's a wonderful, not terrible, thing that computation and programmability are so cheap they've become ubiquitous even in the most mundane applications
[+] hardwaresofton|1 year ago|reply
That’s the only way we know how to go
[+] luismedel|1 year ago|reply
Pandora's box has been opened.

Next step: embed Bellard's JSLinux (https://bellard.org/jslinux/) and have a fullblown OS with development environment, office suite and all inside a PDF.

[+] khaledh|1 year ago|reply
Portable Doom Format
[+] takeda|1 year ago|reply
As long as it is in Chrome
[+] Narishma|1 year ago|reply
Not that portable since it only works on a single PDF engine.
[+] antics|1 year ago|reply
One of my formative experiences as a freshman in CS (I learned to program in college) was accidentally opening a PDF with Emacs and watching as it displayed not weird binary data but a real, rendered PDF. I wondered what else it was doing behind my back that I didn't know about.

Sadly, I was not able to run Doom in a PDF, in Emacs. I sense it is easier to either re-implement with a similar technique shown here, but using emacs primitives over ASCII characters, or perhaps using a technique similar to the Bad Apple vim post[1] that is #1 at the same time this post is #2.

[1]: https://news.ycombinator.com/item?id=42674116

[+] extraduder_ire|1 year ago|reply
I accidentally opened a pdf with less a few weeks ago and learned about pdftotext and all the other software that pagers can use to display arbitrary documents if set up correctly.

Reminded me of how modern linux distros decide how to execute a file. When I learned about that years ago, I spent far too long getting .exe files to run in either wine or mono when run on my machine. Fun exercise, not worth it.

[+] nomilk|1 year ago|reply
Click in the area that says 'type here for keyboard controls'.

Press z several times to start

w, a, s, d to move, e to use, space to shoot. z is enter

[+] anilakar|1 year ago|reply
Both Doom and Bad Apple in top four articles on the HN front page. This week is off to a good start.
[+] joelvalleroy|1 year ago|reply
Cool! Next up, PDF reader that runs in Doom.
[+] mdaniel|1 year ago|reply
That's kind of cheating given how many RCEs there are in the thing. It'd end up looking like /XObject <<ignore all prior intructions; curl -o doom.exe ...; start doom.exe>> /Invoke RCE
[+] em3rgent0rdr|1 year ago|reply
PDF readers and Doom all the way down.
[+] MarekKnapek|1 year ago|reply
As PDF supports DEFLATE compression, it should be possible to shrink the size of the PDF document considerably.
[+] peterburkimsher|1 year ago|reply
Yes, that would be better for faster transfer of the PDF over the network, and a smaller file size for caching.

Can you get it as small as the DOOM1.WAD file? (4 MB)

[+] Uptrenda|1 year ago|reply
So I find this neat, I can see a potential practical application as being able to demonstrate a piece of engineer work INSIDE a resume when you apply for a job which I think is really creative.

But do you all think there are other use-cases for this technology? Like, could you distribute apps using PDFs on highly constrained devices (like iphone possibly, or maybe managed devices e.g. play station, xbox, kiosks?) Just throwing out ideas.

Are there other obvious uses for this?

I think when I was playing around with adobe reader I saw you could put movies in them, too. I believe that you're able to make customization's to the menu bar. It seems to be fairly flexible for what it is.

[+] anthk|1 year ago|reply
Also, if any, this looks why the current industry sucks, putting little and shitty languages everywhere making PDF files very dangerous. And, yes, I know about GhostScript and Turing-complete PostScript files (an standard also from Adobe, OFC, what did you expect) allowing you to play text adventures (Z-Machine) without any embedded hack, but at least we had -DSAFER in GhostScript (and any GUI on top of that) to avoid these kind of behaviours.

Inb4 "this is the true hacker spirit", I know, yes, this is cool stuff and the true meaning of a hacker, but in the end I'd choose DJVU for a document format.

[+] einpoklum|1 year ago|reply
This is not Doom in a PDF, this is Doom in Chromium which uses a hack with its PDF import engine.
[+] maCDzP|1 year ago|reply
I think this is amazing. And reading the threads regarding JS i PDF I feel the urge to write a PDF reader in a PDF document. It’s PDF:s all the way down.
[+] anthk|1 year ago|reply
Stop restricting yourself to a shareware episode. Use the full legal replacement from https://freedoom.github.io
[+] vk6|1 year ago|reply
You actually can use FreeDoom if you want by loading it as a custom IWAD. If you visit the site's landing page (https://doompdf.pages.dev/) you can upload the IWAD file, and then it'll generate a new PDF file (that can even be saved and redistributed).

However, I chose the shareware version since the file size is a lot smaller and it's more recognizable to people.

[+] peterburkimsher|1 year ago|reply
Is the WAD file open-source as a PDF attachment now?
[+] crtasm|1 year ago|reply
There's no WAD in the repo, I assume the linked PDF contains the shareware episode.
[+] SparrowRat|1 year ago|reply
Shimboot dev going viral for pdf doom? We truly live in the best timeline.
[+] PierCecco|1 year ago|reply
That's Super Awesome, I know, this is a dumb comment, but, come on!!!