10

I have some documents that are in a .chm format. I wondered if there is a file format that can be easier to navigate, supported and of equal file size in Ubuntu?

If there is, I would like to start converting all those books and probably using them with less hassle on all my Ubuntu PCs and my Android phone.

2

8 Answers 8

13

You can convert them to PDF using the command line program chm2pdf (install chm2pdf here). Once installed you can run the command from a terminal like this:

chm2pdf --book in.chm out.pdf

In case you didn't know, there are several chm readers available - just search chm in the Software Centre.

You can also extract chm files to html using the command line tool 7-Zip (install p7zip-full here):

7z x file.chm
2
  • Pdf conversion isn't a solution I'm looking for. Yet, thanks for your fast reply. More ideas?
    – Julio
    Feb 27, 2011 at 7:02
  • install does not work, maybe manually
    – Adam
    Nov 22, 2020 at 9:25
4

If you do not want to use PDF then I would suggest Epub, a fairly good, open e-book format, you can install a good reader for it called Calibre on Ubuntu, Calibre has a useful conversion facility that can import chm files and then convert them to other formats epub included. epubs can be easily read on most smart phones and tablets as well.

Calibre can be installed from the software center.

2

There is also KChmViewer, if you prefer KDE.

1
  • KChmViewer is Ok. but I'd prefer the firefox addon [CHM Reader]. Not a good solution for my issue, as I want to get rid of those lousy chm files I already have to a better supported format. Pdf isn't good either. Options?
    – Julio
    Feb 27, 2011 at 7:05
2

There is also xchm and a few chm readers on Android.

2

Calibre will do it all

  1. Install Calibre

  2. import the chm file into Calibre with Add books button

  3. use Convert books button to convert it to epub or pdf.

1
  • This is ultimately what worked for me. On the command line, calibre can be installed with apt and used as ebook-convert to convert the CHM to a PDF.
    – Phoenix
    Jan 24, 2023 at 19:26
1

This is an old question, but a straight-forward answer is to use archmage which can host the chm contents as a website on localhost.

For example run

archmage -p 5000 file.chm

and open http://localhost:5000 in your webbrowser to open the documentation inside the chm file.

Manpage as reference:

http://manpages.ubuntu.com/manpages/trusty/man1/archmage.1.html

1

dv3500ea has a great chm2pdf answer, but I prefer to read them as html files.

In short:

sudo apt-get install libchm-bin
extract_chmLib myFile.chm outdir

Source: http://www.ubuntugeek.com/how-to-convert-chm-files-to-html-or-pdf-files.html

Then open up ./outdir/index.html to view the converted html files! Yaaay! Much better. Now I can navigate it just like a .chm file, but I can also use my Chrome browser to search the pages for text, easily print, etc.

Let's make a command called chm2html

Here's a nice script I wrote.

  1. Copy and paste the below script into a file chm2html.py
  2. Make it executable: chmod +x chm2html.py
  3. Create a ~/bin directory if you don't already have one: mkdir ~/bin
  4. Make a symlink to chm2html.py in your ~/bin directory: ln -s ~/path/to/chm2html.py ~/bin/chm2html
  5. Log out of Ubuntu then log back in, or reload your paths with source ~/.bashrc
  6. Use it! chm2html myFile.chm. This automatically converts the .chm file and places the .html files into a new folder called ./myFile, then it creates a symlink called ./myFile_index.html which points to ./myFile/index.html.

chm2html.py file: get the latest version of this file on GitHub here from my eRCaGuy_dotfiles repo:

#!/usr/bin/python3

"""
chm2html.py
- convert .chm files to .html, using the command shown here, with a few extra features (folder names, shortcuts, etc):
http://www.ubuntugeek.com/how-to-convert-chm-files-to-html-or-pdf-files.html
- (this is my first ever python shell script to be used as a bash replacement)

Gabriel Staples
www.ElectricRCAircraftGuy.com 
Written: 2 Apr. 2018 
Updated: 2 Apr. 2018 

References:
- http://www.ubuntugeek.com/how-to-convert-chm-files-to-html-or-pdf-files.html
  - format: `extract_chmLib book.chm outdir`
- http://www.linuxjournal.com/content/python-scripts-replacement-bash-utility-scripts
- http://www.pythonforbeginners.com/system/python-sys-argv

USAGE/Python command format: `./chm2html.py fileName.chm`
 - make a symbolic link to this target in ~/bin: `ln -s ~/GS/dev/shell_scripts-Linux/chm2html/chm2html.py ~/bin/chm2html`
   - Now you can call `chm2html file.chm`
 - This will automatically convert the fileName.chm file to .html files by creating a fileName directory where you are,
then it will also create a symbolic link right there to ./fileName/index.html, with the symbolic link name being
fileName_index.html

"""


import sys, os

if __name__ == "__main__":
    # print("argument = " + sys.argv[1]); # print 1st argument; DEBUGGING
    # print(len(sys.argv)) # DEBUGGING

    # get file name from input parameter
    if (len(sys.argv) <= 1):
        print("Error: missing .chm file input parameter. \n"
              "Usage: `./chm2html.py fileName.chm`. \n"
              "Type `./chm2html -h` for help. `Exiting.")
        sys.exit()

    if (sys.argv[1]=="-h" or sys.argv[1]=="h" or sys.argv[1]=="help" or sys.argv[1]=="-help"):
        print("Usage: `./chm2html.py fileName.chm`. This will automatically convert the fileName.chm file to\n"
              ".html files by creating a directory named \"fileName\" right where you are, then it will also create a\n"
              "symbolic link in your current folder to ./fileName/index.html, with the symbolic link name being fileName_index.html")
        sys.exit()

    file = sys.argv[1] # Full input parameter (fileName.chm)
    name = file[:-4] # Just the fileName part, withOUT the extension
    extension = file[-4:]
    if (extension != ".chm"):
        print("Error: Input parameter must be a .chm file. Exiting.")
        sys.exit()

    # print(name) # DEBUGGING
    # Convert the .chm file to .html
    command = "extract_chmLib " + file + " " + name
    print("Command: " + command)
    os.system(command)

    # Make a symbolic link to ./name/index.html now
    pwd = os.getcwd()
    target = pwd + "/" + name + "/index.html"
    # print(target) # DEBUGGING
    # see if target exists 
    if (os.path.isfile(target) == False):
        print("Error: \"" + target + "\" does not exist. Exiting.")
        sys.exit()
    # make link
    ln_command = "ln -s " + target + " " + name + "_index.html"
    print("Command: " + ln_command)
    os.system(ln_command)

    print("Operation completed successfully.")
0

Wine is enough .

Then : Open it using this soft

enter image description here

1
  • It's worth mentioning that "%SystemRoot%\hh.exe" is Windows' built-in .chm file viewer. It doesn't solve the OP's question about making the documents easier to navigate - you're still restricted by Microsoft's horrible search functionality in .cm files. Oct 4, 2022 at 21:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .