UTF-8 txt to PDF

Hello,
Do we have a cmd line app to convert UTF-8 text files to PDF?

1 Like

Maybe one of these options: https://www.baeldung.com/linux/convert-text-to-pdf

1 Like

Requires enscript and ps2pdf packages.

credits to oyamo

#!/bin/bash
if [ $# -lt 2 ]; then
echo “Usage: text2pdf ”
exit 1
fi

enscript -B -fCourier10 -p “$2.ps” $1
ps2pdf “$2.ps” $2
rm “$2.ps”

1 Like

Thanks for the hints. At the end I used (and added to my booklet):

57 Converting UTF-8 txt to PDF

   This needs ImageMagick be installed and a small disable change in

   # tail -10 /etc/ImageMagick-6/policy.xml
     <policy domain="path" rights="none" pattern="@*"/>
     <!-- disable ghostscript format types
     <policy domain="coder" rights="none" pattern="PS" />
     <policy domain="coder" rights="none" pattern="PS2" />
     <policy domain="coder" rights="none" pattern="PS3" />
     <policy domain="coder" rights="none" pattern="EPS" />
     <policy domain="coder" rights="none" pattern="PDF" />
     <policy domain="coder" rights="none" pattern="XPS" />
     -->
   </policymap>

   Then you can run:

   $ convert -font Courier TEXT:Reimann-Bestellung.txt PDF:Reimann-Bestellung.pdf

   The resulting PDF file Reimann-Bestellung.pdf looks fine

2 Likes

Probably too late but … you can just use libreoffice e.g.

libreoffice --convert-to pdf test.txt

and, yes, I tested it including non-ASCII characters so that the input .txt file does contain UTF-8 encoding, but not exhaustively tested.

1 Like

ImageMagick convert creates image based PDFs.

irvinewade’s method makes a PDF with about half as many bytes that can be zoomed in or out by large factors and whose text can be copied and pasted as text.

3 Likes

This is true, but the installation of libreoffice costs 1 GByte to convert a 1 KByte UTF-8 txt :slight_smile:

2 Likes

Maybe convert on a server? i.e. offload the task from the phone.

But isn’t it great that the exact same command would work on your desktop / laptop, on your server, on your phone‽

1 Like

Yes, it is. ImageMagic’s convert runs on my L5 and on my FreeBSD laptop. :slight_smile:

2 Likes

Fair enough, but enscript and ghostscript (recommended above by Tonyp) cost about 2 MB and 250 KB for arm64.

1 Like