How to convert ANSI colored text to PDF

I have a program that generates console output colored with ANSI codes. How to convert it to PDF keeping the colours?

I need a unixish command line solution


Solution 1:

The best solution so far: aha to convert to HTML (https://stackoverflow.com/questions/245121/a-library-to-convert-ansi-escapes-terminal-formatting-color-codes-to-html), then convert HTML to PDF e.g. with wkhtmltopdf.

I am still looking for a one step solution.

Solution 2:

I made a script that does ANSI->SVG. You can then convert to pdf with headless Inkscape.

Example:

ls --color | ./ansi_svg.py | inkscape -z -f /dev/stdin --export-pdf=ls.pdf