FileKit
All posts
·6 min read

How to Convert Text to PDF — From Plain Text to Formatted Document

Methods for converting .txt files to well-formatted PDFs — covering browser tools, word processors, command line, and formatting best practices.

When Plain Text Needs to Be a PDF

Plain text files are universal — every operating system can open them, every text editor can read them. But they lack formatting control. There are no margins, no page breaks, no consistent typography. When you open a .txt file on two different computers, the line wrapping, font, and spacing may look completely different.

Converting to PDF locks in the layout. The text renders identically on every device, every screen, every printer. This matters for resumes, code listings, meeting notes, legal transcripts, log files, and any document you need to share professionally or archive reliably.

Methods for Converting Text to PDF

1. Browser-Based Conversion

FileKit's Text to PDF tool lets you type or paste text, choose a page size (A4 or Letter), set font size and margins, and generate a clean PDF instantly. The text is automatically wrapped and paginated. Everything runs in your browser — no upload, no server, no data leaves your device.

2. Word Processors

Open the .txt file in Google Docs, Microsoft Word, or LibreOffice Writer. Format the text as needed — add headings, adjust fonts, set paragraph spacing — then export or "Save as PDF." This approach is best when you need rich formatting beyond what a plain text converter provides.

3. Command Line

# enscript + ps2pdf (classic Unix approach)
enscript -p output.ps --font=Courier10 input.txt && ps2pdf output.ps output.pdf

# pandoc (Markdown/text to PDF via LaTeX)
pandoc input.txt -o output.pdf

# Python one-liner using reportlab
python3 -c "from reportlab.lib.pagesizes import A4; from reportlab.pdfgen import canvas; \
c=canvas.Canvas('out.pdf',pagesize=A4); c.drawString(72,750,open('input.txt').read()); c.save()"

enscript is the classic Unix tool — it converts text to PostScript with configurable fonts, headers, and line numbering.pandoc is more modern and supports Markdown formatting. For scripting and batch processing, Python libraries like reportlab give full programmatic control.

Formatting Options That Matter

Font Choice

The font you choose fundamentally changes how the document reads:

  • Monospace fonts (Courier, Consolas, JetBrains Mono) — Every character occupies the same width. Essential for code listings, log files, and any content where column alignment matters. If you are converting source code or terminal output, always use monospace.
  • Proportional fonts (Helvetica, Times New Roman, Georgia) — Variable character widths produce natural-looking prose. Better for meeting notes, letters, essays, and narrative content.

Page Size

  • A4 (210 × 297 mm) — International standard. Use this for anything that may be printed outside North America.
  • Letter (8.5 × 11 in) — US and Canadian standard. Use when the recipient will print on US-standard paper.

Margins

Standard margins are 2 cm (about 0.8 inches) on all sides for A4, or 1 inch for Letter. Narrower margins fit more text per page but reduce readability and can cause issues with printers that have non-printable edge zones.

Font Size

10-12pt is standard for body text. For code listings that need to fit wide lines without wrapping, 8-9pt works but sacrifices readability. For documents intended for screen reading (not print), 11-12pt is ideal.

Common Use Cases

Code Listings and Documentation

Converting source code files to PDF for code reviews, documentation appendices, or academic submissions. Use a monospace font, enable line numbering if available, and choose a font size small enough to fit your longest lines without wrapping (typically 8-10pt for 80-column code).

Server Logs and Debug Output

System administrators and developers often need to share log files as attachments in bug reports or incident reviews. A PDF preserves the exact formatting, prevents accidental editing, and is universally viewable without requiring the recipient to have a text editor configured for large files.

Meeting Notes and Transcripts

Raw meeting notes taken in a plain text editor need to be distributed to the team. Converting to PDF adds professionalism and ensures everyone sees the same layout. For longer transcripts, consider adding page numbers after conversion.

Legal and Compliance Documents

Plain text exports from databases, email archives, or chat logs often need to be submitted as evidence or compliance records. PDF is the standard format for legal submissions because it preserves content integrity and is widely accepted by courts and regulators.

Handling Special Characters and Encodings

Text files can use different character encodings: UTF-8, ASCII, ISO-8859-1, Shift_JIS, and many others. If your text contains non-Latin characters (Chinese, Japanese, Korean, Arabic, Cyrillic), emoji, or special symbols:

  • Make sure the conversion tool supports UTF-8 encoding. Most modern tools do, but older command-line utilities may default to ASCII.
  • Verify the output PDF displays all characters correctly. Missing glyphs appear as boxes (□) or question marks (?).
  • If characters are missing, the tool may not have the required font embedded. FileKit's browser-based tool handles CJK characters automatically when the browser has the appropriate system fonts.

After Conversion

  • Check line wrapping. Long lines in the original text may wrap differently in the PDF. Verify that code or tabular data still aligns correctly.
  • Verify page breaks. Automatic pagination may split content in awkward places. Some tools let you insert manual page breaks using form feed characters (\f).
  • Compress if needed. Text-only PDFs are usually small, but if you converted a very large log file, consider compressing the PDF before sharing.
  • Make it searchable. PDFs generated from text are already searchable (unlike scanned documents). You can use Ctrl+F / Cmd+F to find any string.

Text to PDF vs. Other Conversions

If your source content is more complex than plain text, a different conversion path may be better:

  • Markdown to PDF — Use pandoc or a Markdown editor with PDF export. You get headings, lists, code blocks, and basic formatting.
  • HTML to PDF — For web content with styling, use a browser's Print to PDF or a dedicated HTML-to-PDF converter.
  • Images to PDF — For scanned documents or photos, use FileKit's Images to PDF tool instead.