Skip to content

Code to PDF

Paste source code in any popular language and get a syntax-highlighted PDF with line numbers — ideal for sharing, printing or attaching to assignments and reviews.

About Code to PDF

Code reads badly when you print it from an editor: the colours vanish, the indentation can wander and there is no way to refer to a line. Here the listing is coloured by language, set in a monospaced face with the indentation preserved exactly, and numbered if you want.

You pick a language from a list of twenty-one, including JavaScript, TypeScript, Python, PHP, Java, C, C++, C#, Go, Rust, Ruby, Kotlin, Swift, SQL, Bash, JSON, YAML, HTML, CSS, XML and Markdown, or leave it on auto-detect and let the colouring guess. Line numbers can be switched off, and the paper is A4 or Letter.

The numbers sit in their own column, not inside the text, so if someone copies a function out of the PDF they get the code and not "14 return x".

When to use Code to PDF

  • Attach a code sample to a job application, where a PDF is easier to open than a repository.
  • Print a listing to review on paper, with line numbers to refer to in the margin.
  • Submit a programming assignment that has to be a document and not a zip of source.
  • Keep a snapshot of a script alongside the documentation that describes it.

Tips for the best result

  • Choose the language yourself when you can. Auto-detect copes with long files and is often wrong for a three-line snippet.
  • Break very long lines yourself before converting; they wrap, but a wrapped line can be hard to follow.
  • Do not paste a whole project. A few well-chosen files are read; forty pages of listing are not.

How to use Code to PDF online

  1. 1

    Upload your file

    Choose a file or drag and drop it onto the page.

  2. 2

    Choose your options

    Adjust the settings if you need to, or keep the sensible defaults.

  3. 3

    Run Code to PDF

    Click the button and your file is processed in seconds.

  4. 4

    Download the result

    Save your new file to your device.

Frequently asked questions

Can I turn the line numbers off?

Yes. There is a switch for it, and the code is then printed on its own.

What if my language is not in the list?

Leave it on auto-detect. If the colouring is wrong, the closest listed language usually looks better than none.

Will tabs and spacing survive?

Yes. Indentation is preserved exactly as you pasted it.

Is Code to PDF free?

Yes. You can use Code to PDF on SnapPDF for free, without creating an account. Paid plans only raise the limits for heavy use.

How do I use Code to PDF?

1. Upload your file. 2. Choose your options. 3. Run Code to PDF. 4. Download the result.

How are my files handled?

Our privacy page explains what happens to your files and how long anything is kept. We never sell your files or use them to train AI.

Do I need to install any software?

No. Code to PDF works in any modern browser on Windows, Mac, Linux, Android and iPhone.

Which file types are supported?

Code to PDF accepts files.

What else can I do with SnapPDF?

SnapPDF has more convert to pdf tools and many others to merge, split, compress, convert, edit and secure PDFs.