PY PDF
File conversion

Convert PY to PDF

QUICK ANSWER
Is it possible to convert PY to PDF?
Yes - PY converts to PDF.

Open the .py file in VS Code, install the vscode-print or PrintCode extension, and save the print output as PDF from the browser dialog. The result is a visual document of the code - not a runnable program.

Also to PDF: LTX · TEX · DWG

On this page

Tested on macOS, Windows & Linux
Last verified Oct 2026

More free converters

HEIC, PNG, WEBP, MP3 and more - every tool here is free.

Open the toolbox

Why convert PY to PDF?

A PDF of Python source code can be opened on any device without a Python installation and is used for code review printouts, documentation, and assignment submission. PDF preserves syntax highlighting and pagination in a fixed layout.

How to convert PY to PDF

VS Code FREE

Open the .py file in VS Code, install the vscode-print or PrintCode extension, use the Print command, then set the browser print destination to Save as PDF.

Pygments (pygmentize) OPEN-SOURCE

Install with pip install pygments (requires a LaTeX distribution for PDF output), then run pygmentize -f pdf -o output.pdf yourfile.py to produce a syntax-highlighted PDF.

Notepad++ FREE

Open the .py file in Notepad++, go to File > Print, and select Microsoft Print to PDF as the printer to save a plain unstyled PDF without syntax highlighting.

Our free PDF toolsAll tools →

About these formats

Quality & what to watch

  • The resulting PDF is a visual snapshot of the code - it cannot be executed and contains no Python runtime data.
  • Pygments requires a LaTeX distribution (TeX Live or MiKTeX) to produce PDF output; if LaTeX is not installed, use -f html to generate an HTML file and print that to PDF from a browser.
  • On macOS, any application's print dialog has a Save as PDF button in the lower left - no extra software is needed for a basic unstyled export.

Frequently asked questions

Will the PDF include syntax highlighting?
VS Code with a print extension and Pygments both produce syntax-highlighted PDFs. Printing from Notepad++ or a basic text editor produces plain unstyled output.
Do I need LaTeX to use Pygments for PDF output?
Yes - pygmentize -f pdf generates a LaTeX file and compiles it. Without LaTeX, use -f html to produce an HTML file and print that to PDF from a browser.
Can I convert multiple .py files to a single PDF?
Not directly with the tools above. Combine separate PDFs afterward using a PDF merge tool, or concatenate the source files first and then convert.