Simple CHM to PDF conversion on Linux and BSD

Published on 2010-01-07. Modified on 2023-09-03.

This is nothing new, but if you ever needed a simple way to convert a document from CHM format into PDF format on Linux or BSD, here's an easy way to do it with a fairly good result.

You need to make sure that chmlib and htmldoc is installed.

On Debian and derived distributions like Devuan you can get them with:

# apt install libchm-bin htmldoc

On Arch Linux and derived distributions it is:

# pacman -S chmlib htmldoc

On FreeBSD it is:

# pkg install chmlib htmldoc

On OpenBSD it is:

# pkg_add chmlib htmldoc

Next, extract the contents from the CHM file:

$ extract_chmLib doc.chm DESTINATION

Where DESTINATION is the destination directory. If the directory doesn't exist, it will be created.

In order to create a single PDF file of size A4 you can use the following command:

$ htmldoc --size a4 --webpage -f doc.pdf DESTINATION/*.html

That's it.