Is there a way to print info/man pages to PDF?

I would like to see info or man pages in PDF format so the formatting displays correctly. I see texi file can be converted (with texi2pdf) but I don't find any texi files with locate. In this case, I'm interested in the Gpg2 info page.


Solution 1:

i=gpg2; info $i | aha | wkhtmltopdf - $i.pdf

creates a decent PDF file.


LibreOffice is also able to convert to PDF:

i=gpg2; info $i > $i && libreoffice --convert-to pdf $i && rm $i

The output can compete with the above solution in my opinion.


Also there's enscript which offers interesting formatting options (seeman enscript):

i=gpg2; info $i > $i; enscript -B -o $i.ps $i; ps2pdf $i.ps $i.pdf && rm $i{,.ps}

info gpg2 | lp -d PDF

makes use of CUPS PDF (you might need to install the cups-pdf package first) to print a PDF file in ~/PDF/ – but it's not as fancy.


i=gpg2; info -ao $i.pdf $i

also works, but the output is plain ugly.

Solution 2:

Others have already answered the question of how to convert info pages to PDF, so I'll cover man pages (the original and best online documentation!).

On most modern Unix systems you can convert man pages to PDF just by using the -Tpdf option to man, but be aware that it will output to stdout so you'll need to redirect it:

man -Tpdf man > manpage.pdf

If, for any reason, your installed version of troff/groff (the formatting engine behind man pages) doesn't support direct PDF output then you can use ps2pdf, part of Ghostscript:

man -Tps man | ps2pdf - manpage.pdf