6

What is a simple way to convert a Unicode text file to PDF on the command line on macOS?

One can open a text file in e.g. TextEdit and print it as a PDF. Is there a command line equivalent?

2 Answers 2

9

The following has been tested on Mac OS 10.12.1.

To convert a Unicode text file text.txt to a pdf file text.pdf:

textutil -convert html test.txt
cupsfilter test.html > test.pdf

To specify font:

textutil -font 'Menlo Regular' -fontsize 11 -convert html test.txt
cupsfilter test.html > test.pdf
3
  • 1
    > cupsfilter release-notes.html > cupsfilter: No filter to convert from text/html to application/pdf. I've tried you method but got this error, maybe do you know what's wrong ?
    – Zohar81
    Aug 2, 2020 at 8:44
  • 1
    @Zohar81 I am afraid not. Since writing this answer I have moved towards a more heavyweight solution where I use XeLaTeX to convert the text file to pdf. Aug 7, 2020 at 8:44
  • It is working in osx Monterey 12.6. Thank you, Anders.
    – aironman
    Oct 17, 2022 at 15:04
1

https://pandoc.org/ can convert from text to PDF (and much more). Basic invocation:

pandoc input.txt -o output.pdf
2
  • This is an online converter which pretty much throws any expected privacy right out the window. For security purposes, I highly suggest people avoid this.
    – Allan
    Mar 25, 2023 at 21:13
  • 1
    @Allan No, it absolutely is not. pandoc.org/installing.html
    – AKX
    May 4, 2023 at 13:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .