Guide
How to convert text to PDF
· 6 min read
You have text — typed, pasted, or sitting in a .txt file — and you need a PDF. The conversion itself is trivial; what matters is picking the method that does not quietly wreck your formatting along the way. Here are five routes, from one click to full programmatic control, and when each one is the right call.
Why plain text and PDF are not the same thing
A .txt file is a stream of characters with no opinion about pages, fonts or margins. A PDF is a fixed-layout document: every glyph has a position, every page has a size, and the file embeds everything a reader needs to render it identically on any screen or printer. Converting one to the other means choosing a page size, a font, a margin, and a rule for where lines wrap — and those choices determine whether the result looks right or not.
If your text is code, a log, a transcript or anything with deliberate line breaks, you want a method that preserves whitespace exactly. If it is prose you plan to style, you want one that lets you set headings and bold. The five methods below sit on that spectrum.
Method 1: paste into a browser converter
The fastest path. Open a text-to-PDF converter in any browser, paste your text (or drop a .txt file), and download the PDF. No account, no install, no waiting.
A client-side converter — one that runs in your browser rather than uploading to a server — has two advantages worth knowing about. First, there is no file-size cap, because nothing is being transmitted. Second, the document never leaves your machine, which matters when the text is a contract, medical notes, credentials or anything else you would not paste into a stranger's website.
The output is a clean, searchable PDF with a monospace or sans-serif font, fixed margins and every line break exactly where you put it. If that is all you need, stop here.
Batch conversion. If you have multiple .txt files, a converter that accepts batch input (like the file-based mode) can take up to 20 files at once and merge them into a single PDF, each file starting on its own page.
Method 2: use a word processor
Open the text in Word, LibreOffice Writer, Pages or any word processor, then export or “Save As” PDF. This gives you full control over fonts, headings, margins, headers, footers, page numbers and everything else you would expect from a typesetting tool.
The trade-off: a word processor treats input as prose and reflows it to the page width. Every intentional line break shorter than the margin gets absorbed into a paragraph, and leading spaces vanish. That is fine for an essay or a letter and destructive for a code listing, a log file or a table aligned with spaces. If whitespace matters, paste into a monospace font and set the paragraph spacing to zero — but at that point you are fighting the tool, and Method 1 does the same thing with less effort.
Method 3: Google Docs (or any cloud editor)
Upload the .txt file to Google Drive and open it with Google Docs, or paste the text into a new document. Then File → Download → PDF. It works on any device with a browser, backs the file up automatically, and lets you share the document before or after exporting.
The same reflow caveat from Method 2 applies: Docs will wrap your text to fit the page, and whitespace-sensitive content will not survive intact. You also need a Google account, and the content passes through Google's servers — fine for most things, worth noting for anything sensitive.
Method 4: command line
If the text is already on disk and you want a PDF without opening a GUI, a handful of CLI tools do it in one command:
- enscript + ps2pdf — available on most Linux and macOS systems.
enscript -p - input.txt | ps2pdf - output.pdf - pandoc — converts between dozens of formats.
pandoc input.txt -o output.pdf(requires a LaTeX engine for PDF output). - cupsfilter — ships with macOS.
cupsfilter input.txt > output.pdf
Command-line tools are scriptable, so they slot into build pipelines, cron jobs and CI workflows. The output is plain: monospace font, default margins, no table of contents. For anything that needs to look polished, use Method 2 or feed the text through Markdown with pandoc for headings and lists.
Method 5: code it yourself
When the conversion is part of a larger workflow — generating reports, exporting user data, archiving logs nightly — you write it once and let it run. Python with FPDF2 or ReportLab, JavaScript with pdf-lib or jsPDF, and Go with gofpdf are the common picks. A minimal script reads the text file, sets a font and page size, lays out lines with word-wrapping, and writes the PDF — about 15 lines of code in most languages.
This is the right choice when you need to convert text to PDF repeatedly, on a schedule, or as part of an application. It is the wrong choice for a one-off conversion where any of the methods above would be done before you finish writing the script.
Which method to pick
| Method | Speed | Strength | Watch out for |
|---|---|---|---|
| Browser converter | Instant | Preserves every line break | No headers/footers styling |
| Word processor | A few clicks | Full formatting control | Reflows text, collapses whitespace |
| Google Docs | Upload → export | Works on any device | Reflows text, needs an account |
| Command line | One command | Scriptable, no GUI needed | Requires install, plain output |
| Code (Python etc.) | Write once, reuse | Full automation | Overkill for a one-off |
Tips that apply to every method
- Check the encoding first. If the text file was saved in a legacy encoding (Windows-1252, Shift-JIS, ISO-8859-1), some converters will garble non-ASCII characters. Re-save as UTF-8 before converting, or use a tool that detects encoding automatically.
- Pick the right page size. A4 is standard outside the US; Letter is standard inside it. If the PDF will be printed, match the paper in the printer. If it will only be read on screen, A4 is the safer default.
- Monospace for data, proportional for prose. Code, logs, tables and anything with columns aligned by spaces needs a monospace font or the alignment breaks. Running text reads better in a proportional font like Helvetica or Times.
- Open the PDF and spot-check. Verify that line breaks land where you expect, no text is clipped at the margin, and special characters (accented letters, em dashes, curly quotes) survived the conversion.
Ready to convert? One click, no signup
Paste your text or drop a .txt file into Text to PDF and the PDF preview appears as you type. Choose your page size, font and margins, then download — free, no account, no watermark, and the file never leaves your browser.