Skip to content

Repository files navigation

py2pdf-idle

Convert Python source files to clean, syntax-highlighted PDFs (IDLE colour style) from the terminal or browser.

Install / run

Use with no install:

npx py2pdf-idle /path/to/script.py

Example:

npx py2pdf-idle ./main.py ./main.pdf --paper letter --no-line-nums

Or install globally:

npm i -g py2pdf-idle
py2pdf-idle /path/to/script.py

CLI formula (copy/paste template)

npx 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-header

If 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.

CLI options

OptionDescriptionDefault
--paper <a4|letter>Page sizea4
--orientation <portrait|landscape>Page orientationportrait
--no-line-numsHide line numbersline numbers on
--no-headerHide filename header/footerheader/footer on
-h, --helpShow help

Features

  • IDLE-style syntax colours
  • A4 and Letter output
  • Optional line numbers
  • Optional filename header/footer
  • Browser preview + export

Local development

npm install
npm run dev

Open http://localhost:3000.

Run CLI locally:

npm run cli -- ./TestPyWebsite.py

For maintainers: publish to npm

npm login
npm pack --dry-run
npm publish

If publish fails with a 2FA/permissions E403, enable npm write protection in account settings and re-authenticate:

npm logout
npm login
npm publish

Deploy web app to Vercel

npm i -g vercel
vercel

IDLE colour reference

Token typeColourExamples
keyword#ff7700def, class, if, return
builtin#900090print, len, range, self
string#00aa00"hello", f-strings, docstrings
comment#dd0000# this is a comment
defname#0000fffunction/class names after def/class
number#00000042, 3.14, 0xFF