How to convert CHM files into PDF files in Ubuntu

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

Incoming search terms:

Related posts

15 thoughts on “How to convert CHM files into PDF files in Ubuntu

  1. 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

    Second

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

    Thanks for the tip :D

    [Reply]

  2. 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.

    [Reply]

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

    [Reply]

    admin Reply:

    @ramakanth
    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

    [Reply]

  4. Hello!

    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.

    tia
    /Gustav

    [Reply]

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

    a million thanx man…..

    [Reply]

  6. I get the following error:
    Traceback (most recent call last):
    File “/usr/bin/chm2pdf”, line 1108, in
    main(sys.argv)
    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
    html_list=get_html_list(cfile)
    File “/usr/bin/chm2pdf”, line 106, in get_html_list
    lister.feed(topicstree)
    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!

    [Reply]

Leave a comment

Your email address will not be published. Required fields are marked *