Convert code to PDF
This turns source code into a PDF that keeps its syntax highlighting and its indentation — free, in your browser, with nothing uploaded. Printing code from an editor usually loses the colour, and pasting it into a word processor usually loses the indentation to autocorrect; both make the result hard to read. Paste the code into a fenced block with a language tag and it is typeset on a tinted panel that redraws on every page the block spans.
Open the editorHow to convert code to PDF
Wrap the code in a fence
Put three backticks and the language name above your code, and three backticks below it — for example ```python.
Pick a monospace font and size
Choose the monospace family and drop to 9 or 10pt so long lines fit without wrapping.
Download the PDF
Click Download PDF. Highlighting, indentation and the panel background are all preserved.
What you get
Real syntax highlighting
Keywords, strings, numbers and comments are coloured by a built-in tokenizer — no screenshot, and the text stays selectable.
Indentation is preserved exactly
Leading whitespace survives intact, so nested blocks stay readable and nothing is silently reflowed.
Panels redraw across pages
A block longer than a page keeps its background and border on every page it continues onto.
Mix code with explanation
Because the document is markdown, headings and prose sit between blocks — good for handouts and reviews.
Why printed code usually comes out wrong
Two things normally go wrong. Printing straight from an editor drops the theme, so you get black text on white and lose the colour that made the structure scannable. Pasting into a word processor is worse: autocorrect capitalises identifiers, smart quotes replace the straight quotes that code needs to compile, and the proportional body font destroys any alignment. Here the code goes through a fenced block, which means it is typeset in a monospace face on a tinted panel with a tokenizer applying the colours. Nothing is autocorrected, and the output is real selectable text rather than an image, so a reader can copy a snippet back out.
Fitting long lines without wrapping
Code has hard line lengths, and a wrapped line is much more disruptive in code than in prose because the indentation no longer signals the structure. Three settings buy you width: reduce the base font size to 9 or 10pt, narrow the margins, and switch the page to landscape for anything genuinely wide. A2 and A3 are not offered, but landscape A4 at 9pt comfortably fits the 100-to-120 character lines most style guides allow. If lines still wrap, the honest fix is usually in the source rather than the page setup — reformat before exporting.
Which languages are highlighted
Highlighting comes from a tokenizer built into the app rather than a large third-party library, which keeps the page fast and means the same colours appear in the preview, the PDF and the HTML export. Tag the fence with the language — ```js, ```python, ```go, ```sql and so on — and keywords, strings, numbers and comments are coloured. An untagged fence, or one tagged with a language the tokenizer does not know, still renders correctly as monospace code on its panel with indentation intact; it simply is not coloured. Nothing breaks, and nothing is silently mangled.
What this does not do
- There are no line numbers in the gutter — add them in the source if you need them.
- Unknown languages render as plain monospace rather than being highlighted.
- There is no import from a repository or a folder of source files.
- Highlighting covers common languages; niche ones fall back to plain code.
Frequently asked questions
- How do I get syntax highlighting?
- Put the language name immediately after the opening three backticks, like ```python. An untagged block still renders as monospace code, just without colour.
- Will my indentation survive?
- Yes, exactly as written. Leading whitespace is preserved and nothing is reflowed, which is the usual failure when code is pasted into a word processor.
- Can I add line numbers?
- Not automatically. If you need them, include them in the source text before pasting it in.
- What happens to a code block longer than one page?
- It continues onto the next page and redraws its background panel and border there, so no code is ever left floating on bare paper.
- Is the code in the PDF selectable?
- Yes. It is real text, not an image, so a reader can copy a snippet straight back out of the PDF.
- How do I stop long lines wrapping?
- Drop to 9 or 10pt, narrow the margins, and switch to landscape orientation for genuinely wide code. Together those fit lines of 100 to 120 characters comfortably.
- Is my source code uploaded anywhere?
- No. The PDF is generated in your browser and the code never reaches a server, which matters if the source is proprietary.
Related converters
Convert markdown to PDF
Convert Markdown to PDF in your browser. Tables, syntax-highlighted code blocks, task lists and headings all render. Free, no account, nothing uploaded.
Convert a README to PDF
Convert a README.md to a PDF with tables, syntax-highlighted code blocks and working links intact. Free, no signup, and nothing is uploaded.
Convert TXT to PDF
Convert a .txt file to PDF free. Drag the file in, adjust the font and margins, and download. Nothing is uploaded and there is no watermark.