Convert PY to PDF in Your Browser
Turn a Python file (.py) into a PDF with proper syntax highlighting and page breaks that do not cut a line in half. No install, no upload, no account: your source code never leaves your device.
Drag and drop, paste, or Tap to select a fileclick to select a file
Files are processed on your device only.
How it works
- Drop, paste, or select your .py file. It is read on your device only.
- Pick page size, font size, and a light or dark code theme.
- Click Print or Save as PDF, ticking Background graphics so the colors print.
Highlighting, indentation, and page breaks
Colouring uses the same TextMate grammar VS Code ships for Python, so keywords, decorators, f-strings, docstrings, and type hints are all distinguished rather than reduced to one shade of grey. Indentation is preserved exactly, which matters more in Python than in most languages, because the whitespace is the block structure.
Pagination is handled for reading rather than for saving paper: a line never breaks across two pages, long lines wrap instead of being clipped at the margin, and the print rules keep code blocks intact wherever possible. See how browser-side rendering works for the parser-to-print pipeline behind every converter here.
This page or the paste box, and the notebook route
Use this page when you have a .py file: it takes the file directly, pins the language to Python instead of guessing from the extension, and handles the encoding for you. Use the code to PDF page when you want to paste a snippet, or when the language is JavaScript, Go, Rust, SQL, or one of the others bundled here.
If what you actually have is a notebook rather than a script, go to IPYNB to PDF, which keeps charts, tables, and tracebacks alongside the code. To strip a notebook down to its code first, the IPYNB to PY converter produces the .py you can then print here.
Frequently asked questions
- Does the PDF run or check my code in any way?
- No. Nothing is executed, imported, or linted. The file is read as text, colored with the same grammar your editor uses, and laid out for print, so a script with a syntax error prints exactly as written. What you get is a readable copy of the source, not a report about it.
- What happens to very long lines?
- They wrap onto the next line rather than being cut off at the page edge, and the tool warns you when the longest line passes about 110 characters. Lower the font size or switch to Letter if the wrapping is distracting. Code blocks are also kept from splitting mid-line across a page break.
- Will the syntax colors actually appear in the PDF?
- Yes, once you tick Background graphics in the print dialog. Browsers strip background colors from printed pages by default, which would flatten the highlighting, so that checkbox matters here and even more with the dark theme.
- Is my source code uploaded?
- No. Reading, highlighting, and rendering all happen in your browser on your own device, with the parsing in a Web Worker. There is no upload endpoint, no account, and it keeps working offline, which is the point for proprietary or unreleased code.