Clioos › Guides › TXT to PDF

How to Convert TXT to PDF

By Clioos 团队

The free offline way is a short ReportLab script: read the text file line by line, draw each line on an A4 page, save. Tested 2 November 2026 with ReportLab 5.1.0 — a 126-byte text file with 4 lines became a 1-page PDF of 1,466 bytes, and pdftotext read all 4 lines back verbatim. Clioos does not offer a TXT-to-PDF tool — this guide teaches the method.

At a glance

Steps

  1. Install ReportLab: pip install reportlab (5.1.0 in the test).
  2. Run a script that reads notes.txt, creates an A4 canvas, and draws each line with drawString(72, y, line), decreasing y by 20 per line, then saves.
  3. Verify: the test file (126 bytes, 4 lines) became notes.pdf, 1 page, 1,466 bytes — and pdftotext returned all 4 lines, starting “Launch notes” and “Line one: ship the guide first.”
  4. Handle the limits before real use: wrap lines longer than the page width yourself, and start a new page (showPage, reset y) when y runs out — otherwise text past the bottom margin is lost.

Worked example (tested 2 November 2026)

Test file: notes.txt, 126 bytes, 4 lines of plain ASCII. Method: ReportLab 5.1.0, A4, Helvetica, 20 points per line.

FileDetail
notes.txt (input)126 bytes, 4 lines
notes.pdf (output)1 page, 1,466 bytes
Round-trip checkpdftotext returned all 4 lines verbatim

The PDF is larger than the text file because a PDF carries page structure and font data around the text. That overhead is normal and small.

What it can't do

Frequently asked questions

Is it free to convert TXT to PDF?

Yes, with ReportLab — free and open source, no per-file charge. OS print-to-PDF also works for one file at a time.

Will the PDF text be searchable?

Yes. Unlike an image packed into a PDF, these lines are real PDF text — pdftotext read all 4 test lines back.

What happens to a very long line?

In the minimal script it is cut off at the page edge. Wrap long lines before drawing, or use a text-wrapping helper.

Can I convert a Word document this way?

No — this is for plain .txt only. A .docx needs its own converter; feeding it to this script would draw binary garbage.


Related guides: How to convert PDF to text · How to convert PDF to Word · How to edit a PDF · All guides · Tool: PDF Probe