9

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

Hennes
  • 64,768
  • 7
  • 111
  • 168
grep
  • 241
  • 2
  • 5
  • Found something close to what I need here: http://stackoverflow.com/questions/245121/a-library-to-convert-ansi-escapes-terminal-formatting-color-codes-to-html and then print HTML as it is described in http://stackoverflow.com/questions/176476/how-can-i-automate-html-to-pdf-conversions – grep Feb 15 '13 at 22:14

3 Answers3

5

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.

grep
  • 241
  • 2
  • 5
1

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

markrages
  • 111
  • 2
0

If you have calibre/pdfcreator/cutepdf kind of utility installed in your environment or computer. You can use lp to send text to printer.

Prateek
  • 66
  • 2