17

The programm a2ps does not support utf-8. At least my version does only support the latin-X encodings:

a2ps --list=encoding

Version:

GNU a2ps 4.14

How can I convert a simple utf-8 text to postscript or pdf?

1
  • 2
    See also this discussion on unix.stackexchange.com which decsribes u2ps in addition to paps.
    – Maxim
    Commented Aug 14, 2019 at 9:35

7 Answers 7

13

If what you actually want is to use a2ps or enscript (which is a similar tool), and if your single need is to use them with some UTF-8 document, you only have to convert your document to ISO-8859-1 or some supported encoding. Various tools allow this. For instance, here is a workflow for enscript (but you can surely do the same with a2ps):

cat document.txt | iconv -c -f utf-8 -t ISO-8859-1 | enscript -o document.ps

But you may lose some characters during the conversion because such encodings have a smaller range than UTF-8.

On the other hand, if UTF-8 is a requirement, you may rather have to look for some recent tool allowing to convert UTF-8 to PDF. I wrote myself a Python program called txt2pdf; you may find it here. Have also a look at tools like pandoc, gimli, rst2pdf or wkhtmltopdf.

8
  • 1
    Using iso-8859-1//TRANSLIT instead of plain iso-8859-1 may save you some iconv: illegal input sequence at position XX errors. Commented Jun 19, 2018 at 14:31
  • txt2pdf seems to convert all UTF-8 characters (which are not ASCII) into small black squares. Commented Oct 17, 2018 at 23:41
  • @RogerHouse Hi, I use txt2pdf on a daily basis for my own document with no trouble. Are you sure you specified a correct font? Commented Oct 18, 2018 at 7:17
  • @ThomasBaruchel I am using /usr/share/fonts/truetype/ubuntu-font-family/UbuntuMono-R.ttf and the result is mostly empty square boxes. Probably I should find another font, but I don't know which one. When I display my text file with cat or look at it with vim or emacs (terminal version), everything is great, but I have not found out how to successfully convert it to PDF. Commented Oct 19, 2018 at 21:45
  • @ThomasBaruchel I should mention that my text document is mostly Unicode characters, not straight ASCII. Commented Oct 19, 2018 at 21:54
4

You can use Vim. Open the file and execute the command :hardcopy > output.ps in normal mode. You can also do this directly from the shell. Executing

$ vim -c ":hardcopy > output.ps" -c ":quit" input.txt

in your shell will open Vim, generate the output.ps, and then close Vim.

1
  • Thanks, it is a great answer - vim is installed on many systems by default. Before reading this answer I was installing one tool after another. Sidenote: in neovim 0.9 the :hardcopy option has been removed and it is advised to use the :TOhtml option instead and afterwards convert the resulting HTML file into PDF.
    – Rob Bar
    Commented Apr 7, 2023 at 17:09
4

Use paps! For instance I use it as follow:

paps --font="Monospace 10" input.txt > output.ps  

and I have no problem with utf encoding. If you need a pdf file then

pdf2ps output.ps 
1
  • Note that v0.7+ is probably preferred.
    – xebeche
    Commented Apr 6, 2021 at 10:01
2

I've gotten acceptable results (for printing code listings) from https://github.com/arsv/u2ps

2

https://gitlab.com/gnomify/u2ps is the replacement of gnome-u2ps.

1
  • Please provide essential details from link because link may get expired in future. Commented Nov 1, 2019 at 4:47
1

If the text file is small, paps converts to text to ps, which then can be fed to ps2pdf. The problem is ps file from paps causes ps2pdf to create a very big pdf file. If that is ok, this is possible. Currently, I am having a large file size pdf from paps.

2
  • 1
    I'm the author of paps. The problem of large files from ps2pdf is no longer true in version 0.7.* . Further version 0.7.* can directly write pdf files, so you don't need ps2pdf anymore. Get the latest version from the git repo. Commented Jul 29, 2020 at 12:39
  • 1
    @DovGrobgeld Just what the doctor ordered for line printer output from mainframe emulators to be sent to a contemporary printer! Thank you!
    – Leo B.
    Commented Feb 23, 2022 at 18:33
0

There's a utility based on gnome libraries and named gnome-u2ps. It has less functionality than a2ps, and it seems that it is not maintained anymore.

2
  • I tried this tool years ago; I don't know if its current conversion engine is better, but at that time I found the result awful. If I remember well, outlines from a TrueType font are converted but the hinting is missing. While it may be suitable for printing the output, it can certainly not be an acceptable solution for creating standalone PDF documents. Commented Jun 26, 2016 at 10:07
  • It seems no longer maintained (it depends on obsolete libraries like gnomeprint)
    – bortzmeyer
    Commented Jul 28, 2016 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.