OxygenPDF
txt-to-pdf
convert-to-pdf
text-files
monospace

TXT to PDF: Convert a Text File Without Wrecking It

RohmanRohman8 min read
TXT to PDF: Convert a Text File Without Wrecking It

I took a 300-line server log and converted it from TXT to PDF with our own converter on its default settings. Fifteen pages came out, and every single line had been broken in two. Same file, font two points smaller and margins a quarter-inch narrower: six pages, and not one line broken.

Nothing was wrong with the converter. A .txt file just doesn't say how big a page is, what font to use, or how wide a line may run, so whatever turns it into a PDF has to decide. Most of the time the defaults are fine. For code, logs and anything lined up in columns, they quietly aren't.

Quick answer: To convert TXT to PDF, open Text to PDF, import the .txt file or paste the text, pick A4 or Letter, set the font size and margin, and download. It sets the text in a monospaced font, so columns stay lined up, and the result is real, selectable text. For 80-column code or logs, use 10 pt with margins of about 0.72 inches. The file never leaves your browser.

What a Text File Doesn't Tell the Converter

A PDF is a set of fixed pages. A text file is a stream of characters and line breaks. Bridging the two means answering four questions the file never asks:

  • How big is a page? A4 (210 × 297 mm) or US Letter (8.5 × 11 in). Letter is a little wider and a little shorter, which changes both the line length and the number of lines per page.
  • What font? A proportional font like the one you're reading looks nicer for prose. It also wrecks anything aligned with spaces, because an i and an M are different widths.
  • How wide is a line? Font size and margins together decide how many characters fit before the converter has to wrap.
  • What happens to a line that's too long? It wraps, or it runs off the page.

Our converter answers the font question for you: everything is set in JetBrains Mono, a monospaced face, where every character is exactly 0.6 of the font size wide. That makes the rest plain arithmetic. At 12 pt each character takes 7.2 points; A4 with one-inch margins leaves 451 points of line, so 62 characters fit. Here is how that moves with the two settings you control:

Characters per line on A4 in a monospaced font: 62 at 12 pt with 1-inch margins, 68 at 12 pt with 0.72-inch margins, 75 at 10 pt, 81 at 10 pt with 0.72-inch margins, 83 at 9 pt

Paper Font size Margins Characters per line Lines per page
A4 12 pt 1 in (default) 62 41
A4 10 pt 1 in 75 49
A4 10 pt 0.72 in 81 52
A4 9 pt 1 in 83 55
Letter 12 pt 1 in 65 38
Letter 10 pt 0.72 in 84 49

Those numbers come from running the converter's own layout code, not from a formula on a napkin. The 80-column line is still the default width of a terminal and the line limit in plenty of style guides, so the row that matters most for source code and logs is 10 pt with 0.72-inch margins: 81 characters on A4, 84 on Letter.

The Ways to Convert TXT to PDF You Already Have

You may not need a website at all.

  • Windows: open the file in Notepad, choose Print, pick Microsoft Print to PDF. You get Notepad's font and whatever page setup it remembers.
  • Mac: open it in TextEdit and choose File → Export as PDF. Plain-text files open in a monospaced font (Menlo, by default). From Terminal, cupsfilter notes.txt > notes.pdf does the same with no window at all.
  • Any browser: drag the .txt file into a Chrome or Edge tab, then Print → Save as PDF. The browser shows text files in a monospaced font and wraps long lines at the window edge. Its default headers and footers stamp the date, the file path and page numbers on every page unless you untick them.
  • Command line, for batches: LibreOffice (soffice --headless --convert-to pdf *.txt) or pandoc with a LaTeX install will do hundreds of files in one go. That's the right tool for a folder of logs, and the wrong one for a single note.

All of these work. The dedicated converter earns its place when you want control over line width without fighting a print dialog, when the text has non-Latin characters, or when you're on a borrowed or locked-down machine where installing anything isn't an option.

Code, Logs and Tables: Keep the Columns

Text that relies on alignment is where TXT to PDF conversion goes wrong, and it tends to go wrong the same way every time.

Long lines wrap. When a line is wider than the page, the converter breaks it at the last space that fits, or mid-word if there isn't one. In prose you won't notice. In a log, every wrapped entry turns into two lines that both look like entries. That was my 15-page result: log lines of around 65 characters, a 62-character page, and 300 lines turned into 595. Make the line fit instead: drop to 10 pt, or narrow the margins, using the table above.

Indentation has to survive. Leading spaces are kept exactly as typed, so a Python file or a YAML config keeps its structure. A line that does wrap restarts at the left margin, without the original indent.

Tabs are the sneaky one. A tab isn't a character with a shape. It's an instruction to jump to the next tab stop, and fonts don't draw it. While writing this post I found our converter getting that wrong: it handed raw tabs to the font, the font had no glyph for them, and every tab in a tab-indented file came out as a little "□" box. Go source, Makefiles and tab-separated data were all affected. That's fixed now. Tabs are expanded to spaces at 8-column stops before layout, the same width the text box on the tool page shows, so a tab-aligned table lines up in the PDF the way it does on screen.

If you want the code to look like code, with syntax colours, line numbers and a heading, a plain text converter is the wrong tool. Wrap it in a Markdown code block and use Markdown to PDF instead. There's a whole post on what survives that route.

Encoding, Accents and Other Alphabets

A .txt file is just bytes, and the converter has to guess which character each byte means. The tool reads files as UTF-8, which is what almost everything writes today. Notepad switched its default to UTF-8 in Windows 10 version 1903. An older file saved in a legacy Windows encoding (Notepad called it "ANSI") will show accented letters as � replacement marks. If that happens, open the file, save it again as UTF-8, and re-import it, or paste the text straight into the box instead.

Once the text is decoded, other alphabets are covered. JetBrains Mono handles Latin, Greek and Cyrillic. For Arabic, Hebrew, Devanagari, Thai, Chinese, Japanese and Korean, the converter loads a matching Noto font for those runs of text, so a log line with a Japanese file name in it renders correctly instead of turning into blank space. Characters no loaded font can draw, emoji mostly, come out as a visible "□" rather than silently disappearing, so you can tell something is missing.

How to Convert a TXT File to PDF

  1. Open Text to PDF. Click Import .txt or drop a .txt file on the text box. For other plain-text files, like .log, .csv or source code, open them in any editor and paste the contents in. The importer only accepts .txt.
  2. Pick A4 or Letter.
  3. Set Font Size (8 to 24 pt) and Page Margin (0.5 to 1.5 inches). For prose, the 12 pt default reads well. For code or logs, aim for the line width you need from the table above.
  4. Convert and download. A 300-line log came out as a 28 KB PDF, with the font subset embedded so it looks the same on every device.

The text stays text. You can select it, search it, and copy it back out. That also means PDF to Text can recover it later, which a scan-and-print workaround would have lost.

What This Converter Won't Do

It makes plain pages of plain text, on purpose. A few things it leaves to other tools:

  • Headers, footers and page numbers. Run the PDF through Add Page Numbers or Add Header & Footer afterwards.
  • Formatting. Asterisks stay asterisks. If your text is really Markdown, Markdown to PDF renders headings, lists and code blocks.
  • Page breaks from the file. A form-feed character, which old printouts and some RFC text files use to start a new page, becomes a blank line. Pagination comes from the page size and font, nothing else.
  • Fonts other than monospaced. It's the right choice for anything with alignment and a perfectly readable one for prose. For typeset documents, write them in a word processor and use Word to PDF.

Frequently Asked Questions

How do I convert a TXT file to PDF for free?

Open Text to PDF, import the .txt file or paste its text, choose the page size, font size and margin, then download the PDF. It's free with no sign-up, and the conversion happens in your browser, so the file isn't uploaded anywhere.

Will the text in the PDF be searchable?

Yes. The converter writes real text with an embedded font, not a picture of the text, so you can search, select and copy it in any PDF viewer.

Why are my lines breaking in the middle?

They're longer than the page is wide at your font size. A4 with 1-inch margins fits 62 characters per line at 12 pt and 81 at 10 pt with 0.72-inch margins. Lower the font size or narrow the margins until your longest line fits.

Can I convert a Notepad file to PDF on Windows without software?

Yes, two ways. In Notepad, use Print and choose Microsoft Print to PDF. Or open Text to PDF in your browser and import the file, which gives you control over font size and margins without a print dialog.

Does it work with code or tab-separated files?

Yes. The text is set in a monospaced font, leading spaces are preserved, and tabs are expanded to 8-column stops, so indentation and tab-aligned columns line up. Paste code files in, since the importer only accepts .txt. There's no syntax highlighting. For that, use Markdown to PDF with a code block.

Why do accented letters show up as � after converting?

The file was saved in a legacy encoding rather than UTF-8. Re-save it as UTF-8 (in Notepad, choose UTF-8 in the Save As dialog's Encoding menu), then import it again, or paste the text directly into the converter.

Pick the Line Width, Then Convert

Most text files convert fine on the defaults. The ones that don't are the ones where alignment carries meaning: logs, code, fixed-width tables. For those, decide how wide your longest line is, pick the font size and margin that fit it, and you'll get a PDF that reads like the file did.

Convert your text file to PDF in your browser, with no upload and no install.

Rohman

Written by

Rohman

Rohman built OxygenPDF's client-side PDF toolkit, including its Text to PDF converter and the font engine behind it, and writes about what actually happens to a document when you process it in a browser instead of uploading it.

Share this articlePost on XLinkedIn

Stop renting your PDF platform.

All 119+ tools free on web. Desktop Pro is $29 once — every desktop tool, the workspace, and batch processing.

  1. $29now
  2. $79after that

14-day money-back guarantee • Works offline • All platforms

We use analytics to understand how our tools are used and improve the experience. No personal files are ever sent.