Skip to content
Text to PDF

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

MethodSpeedStrengthWatch out for
Browser converterInstantPreserves every line breakNo headers/footers styling
Word processorA few clicksFull formatting controlReflows text, collapses whitespace
Google DocsUpload → exportWorks on any deviceReflows text, needs an account
Command lineOne commandScriptable, no GUI neededRequires install, plain output
Code (Python etc.)Write once, reuseFull automationOverkill 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.

Questions about converting text to PDF

Does converting text to PDF change the text?

No. A PDF stores the exact characters you gave it — nothing is reworded, spell-checked or reformatted beyond the page dimensions and font you chose. What goes in is what comes out, byte for byte in the text layer.

Can I convert a .txt file to PDF without installing anything?

Yes. A browser-based converter like Text to PDF lets you drop a .txt file (or up to 20 at once) and download the PDF immediately. The conversion runs client-side in your browser, so the file is never uploaded to a server.

Will the PDF be searchable?

If the source is real text — typed, pasted, or read from a .txt file — the resulting PDF is fully searchable and selectable. PDFs only lose searchability when the source is a scanned image with no text layer.

Is there a file-size limit for text-to-PDF conversion?

Server-based converters usually cap uploads at a few megabytes. A client-side converter has no upload limit because nothing leaves your machine — the practical ceiling is your browser's available memory, which comfortably handles files of tens of megabytes.

How do I keep my line breaks and indentation?

Use a converter that treats the input as pre-formatted text and renders it in a monospace font. Word processors reflow text to fit the page width, which collapses intentional whitespace. A dedicated text-to-PDF tool preserves every line break and leading space exactly as written.

Can I merge multiple text files into one PDF?

Yes. Drop all the files into a converter that supports batch input, choose whether each file starts on a new page or continues where the last one ended, and download a single merged PDF.

Keep reading