Running LLMs inside PDFs, one 5-second token at a time
A proof-of-concept that compiles llama.cpp to asm.js and base64-encodes a GGUF model so a PDF viewer can execute LLM inference entirely on its own.
What it does
llm.pdf is a stunt build that runs large language model inference entirely inside a PDF viewer. It uses Emscripten to compile llama.cpp into asm.js, then injects that JavaScript into a PDF alongside a base64-encoded GGUF model. The result is a single .pdf file that performs token generation without ever leaving your document reader.
The interesting bit
The project hijacks an old PDF JavaScript injection technique to execute the compiled inference engine, turning what is normally a static document format into a weird, self-contained compute container. It is essentially a technical demonstration that the boundary between “document” and “application” is thinner than your PDF reader would like.
Key highlights
- Compiles
llama.cppto asm.js via Emscripten for execution inside PDF JavaScript - Embeds the entire quantized model into the PDF using base64 encoding
- Supports custom GGUF models via
scripts/generatePDF.py - Targets tiny models around 135M parameters; the README notes these already take roughly five seconds per token
- Extends the “run unexpected things in PDFs” genre, following prior art like DoomPDF
Caveats
- Performance is glacial: 135M parameter models run at roughly five seconds per token, and anything larger is considered “unreasonably slow”
- Only GGUF quantized models are compatible, and Q8 quantization is recommended for best (relative) speed
- This is explicitly a proof-of-concept, not a practical deployment strategy
Verdict
Grab this if you enjoy security-adjacent stunts, Emscripten oddities, or need a party trick to horrify your DevOps team. Skip it if you are looking for an actual production inference engine.
Frequently asked
- What is EvanZhouDev/llm.pdf?
- A proof-of-concept that compiles llama.cpp to asm.js and base64-encodes a GGUF model so a PDF viewer can execute LLM inference entirely on its own.
- Is llm.pdf open source?
- Yes — EvanZhouDev/llm.pdf is an open-source project tracked on heatdrop.
- What language is llm.pdf written in?
- EvanZhouDev/llm.pdf is primarily written in Python.
- How popular is llm.pdf?
- EvanZhouDev/llm.pdf has 870 stars on GitHub.
- Where can I find llm.pdf?
- EvanZhouDev/llm.pdf is on GitHub at https://github.com/EvanZhouDev/llm.pdf.