June 27, 2008 · General · Email This Post

Sponsored Link
If you want to convert .chm file to .pdf file you need to install chm2pdf application.This is A Python script that converts CHM files into PDF files. The package supports batch conversion, command line, PDF security options, password protection and compression modes. The program has Explorer-like interface.

Install chm2pdf in ubuntu

sudo aptitude install chm2pdf

Using chm2pdf

chm2pdf syntax

/usr/bin/chm2pdf [options] input_filename [output_filename]

chm2pdf examples

Unstructured HTML files inside the CHM file, use of --webpage option -- produces my-file.pdf:

chm2pdf --webpage my-file.chm

Structured HTML files:

chm2pdf --book my-file.chm

Structured HTML files, produce a table of contents page automatically (--title option):

chm2pdf --book --title my-file.chm

Structured HTML files, produce a table of contents page automatically (--title option), add a "titlepage" as found in the toc.html file inside the CHM:

chm2pdf --book --title --titlefile toc.html my-file.chm

If the file "toc.html" is not found, a warning will be issued and the option will be ignored -- just browse the (very verbose) output of chm2pdf to see that warning if you suspect you mispelled the titlefile name.

Like above, now with an explicitly set page size and maximum compression level for the resulting PDF:

chm2pdf --book --title --titlefile toc.html --size 177.8×233.3mm --compression 9 my-file.chm

Like above, but name the PDF "your-file.pdf":

chm2pdf --book --title --titlefile toc.html --size 177.8×233.3mm --compression 9 my-file.chm your-file.pdf

A very interesting option (and one that is not htmldoc-specific, but is pure chm2pdf-specific) is the --extract-only option:

chm2pdf --extract-only my-file.chm

will extract the contents of my-file.chm (all the HTML and other, "special", files inside the CHM) into the directory CHM2PDF_TEMP_ORIG_DIR/my-file. Thus, if CHM2PDF_TEMP_ORIG_DIR has its default value "/tmp/chm2pdf/orig", chm2pdf will extract the file into /tmp/chm2pdf/orig/my-file and stop. You can then examine the extracted files at your pace. They will be overwritten next time you call chm2pdf with the same file(name).

If you want to know more available options use the following command from your terminal

chm2pdf --help

Sponsored Link

Related posts

15 Comments to “How to convert CHM files into PDF files in Ubuntu”

  1. Steve says:


    A million thanks to whoever packaged this for Ubuntu/Debian!

  2. Bytevic says:

    I have Ubuntu 7.10, and the ch2pdf package doesn’t exists, The solution? Easy:

    First install this packages:

    sudo aptitude install libchm-bin libchm-dev htmldoc python-chm


    Download de chm2pdf script on this site: http://code.google.com/p/chm2pdf/

    Thanks for the tip 😀

  3. Shakhaoat says:

    great help man.
    with your permission, can I post the link of this webpage in my blog?

  4. admin says:

    yes you can post the source link

  5. octo says:

    the only way I could get chm2pdf to work was with --continuous option, it wouldn’t work with --book or --title… could be because of my RFTM syndrome.. either way I hope this helps some people.

  6. ramakanth says:

    hi, iam very new to kubuntu. how can i open .chm files without converting to pdf format

  7. admin says:

    Try to install kchmviewer using the following command

    sudo apt-get install kchmviewer

    That’s it after completing the installation you should be able to view .chm files

  8. Arthur says:

    hi, iam very new to ubuntu. im using hardy heron. how can i open .chm files without converting to pdf format? thanks..

  9. arthur says:


  10. Gustav Lundberg says:


    Question about chm2pdf.

    Don’t know if this the right place to ask.
    If not please redirect me!

    Also don’t know if I have missed something in the “–help” menu of chm2pdf.
    If so enlighten me please!

    Q: In Ubuntu 9.10:
    Using xCHM v.1.17 to read .chm-file works fine, Pictures showing up.
    But after having converted to .pdf-file vith chm2pdf 0.9.1 …..
    No more pictures.
    A feature or a bug?

    Size of .chm-file = 170KB.
    Size of .pdf-file = 340KB.


  11. echo9 says:


    thanx man

  12. vineeth says:

    chm2pdf –book –title –titlefile toc.html –size 177.8×233.3mm –compression 9 my-file.chm your-file.pdf

    a million thanx man…..

  13. Anonymous says:

    I get the following error:
    Traceback (most recent call last):
    File “/usr/bin/chm2pdf”, line 1108, in
    File “/usr/bin/chm2pdf”, line 1102, in main
    convert_to_pdf(cfile, filename, outputfilename, options)
    File “/usr/bin/chm2pdf”, line 317, in convert_to_pdf
    File “/usr/bin/chm2pdf”, line 106, in get_html_list
    File “/usr/lib/python2.7/sgmllib.py”, line 103, in feed
    self.rawdata = self.rawdata + data
    TypeError: cannot concatenate ‘str’ and ‘NoneType’ objects

    Please help!

Leave a Reply

  • Recent comments