Sooner or later somebody asks for code as a PDF. A university wants your source submitted as a document. An audit needs a log file as evidence. A client asks for a config snapshot they can annotate. A court filing needs a plain-text exhibit in a fixed format.
Converting it is easy. Converting it so it's still readable takes one decision that most people get wrong.
The one thing that matters: use a monospace font
Code and logs depend on alignment. Indentation carries meaning. Columns line up. A stack trace is legible because everything sits in the right place.
A proportional font (Serif or Sans) gives every character a different
width — an i is narrow, an M is wide. Render code in one and your
indentation drifts, your columns stop lining up, and an aligned log table
turns into a ragged mess. It's still technically readable, and it looks
amateurish.
Monospace gives every character an identical width. That's what your code editor uses, and it's what preserves the alignment on the page.
If you take one thing from this guide: set the font to Monospace.
The steps
Open Blackpdf's TXT to PDF tool and provide your content either way:
- Upload the file — a
.txtfile, or any plain-text file you've renamed (.log,.py,.json,.confare all just text). - Paste it — quicker for a snippet, a stack trace, or something copied out of a terminal.
- Upload the file — a
Set the Font to Monospace. This is the important one.
Set the Page size. A4 or Letter for a normal document. Choose A3 if you have long lines you don't want wrapping (more on that below).
Set the Font size. Smaller fits more per line and per page — useful when your lines are long. Larger is easier to read on paper.
Click Convert to PDF and download.
Dealing with long lines
Long lines are the second problem. A 140-character log line or a deeply indented function won't fit across an A4 page at a comfortable font size, so it wraps — and a wrapped line of code is genuinely confusing to read, because the continuation looks like a new statement.
Three levers, in order of preference:
- Reduce the font size. The simplest fix, and it costs nothing but squinting. It fits substantially more characters per line.
- Use a bigger page. A3 gives you far more width. Slightly odd to print, but excellent if the PDF is for on-screen review.
- Rewrap the source first. If you control the content, hard-wrapping long lines at a sane width in your editor before converting gives you control over where the breaks happen, rather than letting the page decide.
Common questions
Will my code be syntax-highlighted?
No — plain text in means plain text out. There's no colouring or language awareness. If you need syntax highlighting, render the code to HTML first (most editors and many tools can export highlighted HTML) and then use HTML to PDF, which preserves the CSS colours. Remember to turn Background graphics on so a dark theme actually renders.
Can I convert a .py, .js, .json, or .log file directly?
Those are all plain text files with a different extension. The simplest
route is to open the file, copy the contents, and paste them into the
tool — or rename a copy to .txt and upload it.
Is the text in the PDF selectable and searchable?
Yes. You started from real text, so the output is genuinely selectable and searchable — no OCR needed. That matters if the PDF is evidence someone will need to search.
My indentation looks wrong.
You're on a proportional font. Switch to Monospace and it will line up exactly as it does in your editor.
How do I add line numbers?
The converter renders the text as given, so add line numbers to the source
before converting (most editors can paste with line numbers, or a quick
cat -n / nl does it on the command line). Note that
PDF page numbers are a different
thing — they number the pages, not the lines of code.
Can I combine several source files into one PDF?
Convert each file, then merge them into a single document — handy for submitting a whole project as one file.
Wrap-up
- Upload or paste your code/log into TXT to PDF.
- Set the Font to Monospace — this is the whole game.
- Shrink the font size (or step up to A3) if long lines are wrapping.
- Convert to PDF and download.
Monospace preserves alignment; a proportional font destroys it. Everything else is a detail. For the general text-conversion options, see our TXT to PDF guide.
