{"id":25197709,"url":"https://github.com/ading2210/linuxpdf","last_synced_at":"2025-05-14T02:10:16.674Z","repository":{"id":275198717,"uuid":"916802481","full_name":"ading2210/linuxpdf","owner":"ading2210","description":"Linux running inside a PDF file via a RISC-V emulator","archived":false,"fork":false,"pushed_at":"2025-02-02T12:26:15.000Z","size":384,"stargazers_count":3674,"open_issues_count":0,"forks_count":136,"subscribers_count":26,"default_branch":"main","last_synced_at":"2025-04-09T03:08:39.697Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://linux.doompdf.dev","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ading2210.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-14T19:36:42.000Z","updated_at":"2025-04-09T02:09:59.000Z","dependencies_parsed_at":"2025-03-11T23:44:09.587Z","dependency_job_id":null,"html_url":"https://github.com/ading2210/linuxpdf","commit_stats":null,"previous_names":["ading2210/linuxpdf"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ading2210%2Flinuxpdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ading2210%2Flinuxpdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ading2210%2Flinuxpdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ading2210%2Flinuxpdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ading2210","download_url":"https://codeload.github.com/ading2210/linuxpdf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254053362,"owners_count":22006717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-10T02:02:24.961Z","updated_at":"2025-05-14T02:10:11.660Z","avatar_url":"https://github.com/ading2210.png","language":"C","readme":"# LinuxPDF\n\nThis is Linux running inside a PDF file via a RISC-V emulator, which is based on [TinyEMU](https://bellard.org/tinyemu/).\n\nTry it here: [linux.pdf](https://linux.doompdf.dev/linux.pdf)\n\nhttps://github.com/user-attachments/assets/7e992dd1-41a5-4d32-87cc-878b395e3d92\n\nSee also: [DoomPDF](https://github.com/ading2210/doompdf)\n\n## Explanation\n\nThis works in a very similar way to my previous [DoomPDF](https://github.com/ading2210/doompdf) project.\n\nYou 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. \n\nThe full specfication for the JS in PDFs was only ever implemented by Adobe Acrobat, and it contains some ridiculous things like the ability to do [3D rendering](https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#annot3d), make [HTTP requests](https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#net-http), and [detect every monitor connected to the user's system](https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#monitor). However, on Chromium and other browsers, only a tiny subset of this API was ever implemented, due to obvious security concerns. With this, we can do whatever computation we want, just with some very limited IO.\n\nC code can be compiled to run within a PDF using an old version of Emscripten that targets [asm.js](https://en.wikipedia.org/wiki/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 input and output, I reused the same display code that I used for DoomPDF. It works by using a separate text field for each row of pixels in the screen, whose contents are set to various ASCII characters. For inputs, there is a virtual keyboard implemented with a bunch of buttons, and a text box you can type in to send keystrokes to the VM.\n\nThe largest problem here is with the emulator's performance. For example, the Linux kernel takes about 30-60 seconds to boot up within the PDF, which over 100x slower than normal. Unfortunately, there's no way to fix this, since the version of V8 that Chrome's PDF engine uses has its [JIT compiler disabled](https://source.chromium.org/chromium/_/pdfium/pdfium/+/012fe571c9fe430da68dbcd2f5ba21758db0ae15:fpdfsdk/fpdf_view.cpp;l=1211-1214;drc=b69783fd189976dd4625c7dcd9c07921b94d4a3c;bpv=0;bpt=0), destroying its performance.\n\nFor the root filesystem, there are both 64 and 32 bit versions possible. The default is a 32 bit buildroot system (which was prebuilt and taken from the original TinyEMU examples), and also a 64 bit Alpine Linux system. The 64 bit emulator is about twice as slow however, so it's normally not used. \n\n## Build Instructions\n\nClone this repository and run the following commands:\n```\npython3 -m venv .venv\nsource .venv/bin/activate\npip3 install -r requirements.txt\n./build.sh\n```\nIf you want to build the 64 bit rather than 32 bit version, edit `build.sh` and change the `BITS=\"32\"` line.\n\nThe `build.sh` script will download Emscripten `1.39.20` automatically. You must be on Linux to build this. \n\nThe generated files will be in the `out/` directory. Then you can run `(cd out; python3 -m http.server)` to serve the files on a web server.\n\n## Credits\n\nThis project was made by [@ading2210](https://github.com/ading2210/).\n\nThe RISC-V emulator is forked from [TinyEMU](https://bellard.org/tinyemu/), which was written by [Fabrice Bellard](https://bellard.org/).\n\n## License\n\nThis repository is licensed under the GNU GPL v3.\n\n```\nading2210/linuxpdf - Linux running inside a PDF file\nCopyright (C) 2025 ading2210\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program.  If not, see \u003chttps://www.gnu.org/licenses/\u003e.\n```\n","funding_links":[],"categories":["CPU_RISC-V","C"],"sub_categories":["资源传输下载"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fading2210%2Flinuxpdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fading2210%2Flinuxpdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fading2210%2Flinuxpdf/lists"}