11

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.

Kevin Bowen
  • 20,055
  • 57
  • 82
  • 84
Julio
  • 313

8 Answers8

14

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
Kevin Bowen
  • 20,055
  • 57
  • 82
  • 84
dv3500ea
  • 37,734
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.

Sabacon
  • 41,474
3

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.

Levon
  • 131
3

There is also KChmViewer, if you prefer KDE.

Asmerito
  • 376
3

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

elmicha
  • 9,960
2

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

This file is part of eRCaGuy_dotfiles: https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles

""" 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

INSTALLATION INSTRUCTIONS:

  • See my answer here: https://askubuntu.com/a/1021427/327339
  1. Create a ~/bin directory if you don't already have one: mkdir ~/bin
  2. Make a symlink to chm2html.py in your ~/bin directory: ln -s ~/path/to/chm2html.py ~/bin/chm2html
  3. Log out of Ubuntu then log back in, or reload your paths with: source ~/.bashrc
  4. 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.

References:

  • ***** [MY OWN ANSWER with this code] https://askubuntu.com/a/1021427/327339
  • 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.")

Gabriel Staples
  • 11,502
  • 14
  • 97
  • 142
2

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

P.R.
  • 121
0

Wine is enough .

Then : Open it using this soft

enter image description here