Print Code to PDF with Syntax Highlighting

Print code to PDF with syntax highlighting intact: paste a snippet, choose its language, and save a colored PDF, all in your browser. Your code never leaves your device, and the tool keeps working offline.

Code is processed on your device only.

How it works

  1. Paste your code and pick its language from the list.
  2. Choose page size and a light or dark theme.
  3. Click Print or Save as PDF, and enable Background graphics so the colors print.

Why printed code loses its colors, and how this keeps them

Highlighting comes from wrapping each token in a colored span. When you print, browsers default to an ink-saving mode that strips background colors and can flatten text color, which is why code so often comes out plain black on white. Two things have to line up to prevent that: the document must declare the print-color-adjust property on the code, and you must tick "Background graphics" in the print dialog.

This converter sets that CSS for you and reminds you which box to check, so the colors survive to the PDF. See how browser-side rendering works.

Languages, themes, and how long files paginate

Tokens are colored with the same TextMate grammars VS Code uses, so the result matches what you see in the editor. Sixteen languages are bundled, and both a light and a dark theme are available; the dark theme needs the print dialog's background option to render its panel color.

A short snippet stays whole on one page, while a long file paginates with every line kept intact rather than split. For a document that mixes code with prose, headings, and tables, the Markdown to PDF converter highlights fenced code the same way, and for pretty-printed data the JSON to PDF converter adds a table view.

Frequently asked questions

Which languages get highlighting?
Sixteen grammars are bundled: Python, JavaScript, TypeScript, TSX, Bash, JSON, YAML, HTML, CSS, SQL, Rust, Go, Java, C/C++, Markdown, and diff. Any language outside that set still prints, but as plain monospace text rather than colored tokens, so pick the closest match or Plain text for anything unlisted.
Why did my PDF print in black and white?
Browsers drop background and often flatten text colors when printing to save ink. The converter sets print-color-adjust so the highlighting is preserved, but you also have to enable "Background graphics" in the print dialog. With both in place, the colors reach the PDF; miss the checkbox and they vanish.
Can I convert a whole source file, not just a short snippet?
Yes. Paste code of any length into the box. A short block stays together on one page, and a long file flows across pages with each line kept intact, so no line is ever split down the middle. The language you pick applies to the whole paste.
Is my code uploaded anywhere?
No. Highlighting and PDF rendering run entirely in your browser on your device. The code never leaves the machine, there is no account, and the converter keeps working with the network disconnected.

Related tools

Related guides