Convert Python source files to clean, syntax-highlighted PDFs (IDLE colour style) from the terminal or browser.
Use with no install:
npx py2pdf-idle /path/to/script.pyExample:
npx py2pdf-idle ./main.py ./main.pdf --paper letter --no-line-numsOr install globally:
npm i -g py2pdf-idle
py2pdf-idle /path/to/script.pynpx formula
npx py2pdf-idle <python-file-path> [output-file-name.pdf] [options]local repo formula
npm run cli -- <python-file-path> [output-file-name.pdf] [options]Example:
npx py2pdf-idle ./examples/main.py ./exports/main.pdf --paper letter --orientation landscape --no-line-nums --no-headerIf output-file-name.pdf is omitted, the output defaults to the input filename with .pdf.
Not sure what flags you need? The website has a CLI builder — fill in your file path and options and it generates the exact command to copy/paste.
| Option | Description | Default |
|---|---|---|
| `--paper <a4 | letter>` | Page size |
| `--orientation <portrait | landscape>` | Page orientation |
--no-line-nums |
Hide line numbers | line numbers on |
--no-header |
Hide filename header/footer | header/footer on |
-h, --help |
Show help | — |
- IDLE-style syntax colours
- A4 and Letter output
- Optional line numbers
- Optional filename header/footer
- Browser preview + export
npm install
npm run devOpen http://localhost:3000.
Run CLI locally:
npm run cli -- ./TestPyWebsite.pynpm login
npm pack --dry-run
npm publishIf publish fails with a 2FA/permissions E403, enable npm write protection in account settings and re-authenticate:
npm logout
npm login
npm publishnpm i -g vercel
vercel| Token type | Colour | Examples |
|---|---|---|
| keyword | #ff7700 |
def, class, if, return |
| builtin | #900090 |
print, len, range, self |
| string | #00aa00 |
"hello", f-strings, docstrings |
| comment | #dd0000 |
# this is a comment |
| defname | #0000ff |
function/class names after def/class |
| number | #000000 |
42, 3.14, 0xFF |