I’ve tried a lot of ways to do this thing in Linux (Ubuntu) and finally I found the easiest one to use.
Called simply as ‘chm2pdf‘, this is a small script written in Python and it uses a few dependencies you might have to install first.
Now to install it, simply follow this guide:
1. Install dependencies by running in the Terminal:
sudo apt-get install htmldoc libchm-bin python-chm
2. Download chm2pdf by clicking this.
3. Now extract the downloaded file.
4. Open your Terminal and browse to the folder you extracted and run:
sudo python setup.py install
5. You’re done!
Now to use it is very simple:
In Terminal, type:
chm2pdf --book filename.chm # (Where filename is obviously your required file to be converted.)
And surprise surprise, a PDF copy will be waiting for you just next to your CHM file!
I tried chm2pdf, but it simply refused to work. Threw out an extended list of options …but no output at all.
Did this really work for you?
Orthodoc
7 Dec 07 at 10:27 am
Its worked for 5 out of 6 CHM files I had. The PDFs came out quite nice as well.
You can perhaps try this: http://www.karakas-online.de/forum/viewtopic.php?t=10275
Its a slightly more advanced script than the original.
Also, what error specifically? The vanilla one has no option list actually, or does it?
Harsh
7 Dec 07 at 10:31 am
you might want to include the fact that you need to either use the –book or –webpage options…..just successfully converted a chm file for the first time wiht this program and I needed to use the –webpage option
chronniff
8 Dec 07 at 1:41 am
chronniff – Thanks for the correction. I realized I was using version 0.7! Now got the 0.9 one (I thought it was 0.9 itself, before).
Harsh
8 Dec 07 at 8:19 am
[...] Convert CHM files to PDF in Linux sudo apt-get install htmldoc libchm-bin python-chm (tags: howto linux tools chm pdf ubuntu tips htmldoc libchm python apt-get) [...]
links for 2007-12-28 « .$null@dscape/07
29 Dec 07 at 12:50 am
just to be clear, the options you pass to chm2pdf need to be preceded by “–” (i.e. two dashes). The code snippet in the blog post uses only one dash, hence the list of options reported above. anyhow, thanks for the tips.
bviking
5 Mar 08 at 4:42 pm
Happened it:
Removing any previous temporary files
sh: Syntax error: “(” unexpected
sh: Syntax error: “(” unexpected
sh: Syntax error: “(” unexpected
sh: Syntax error: “(” unexpected
Traceback (most recent call last):
File “/usr/bin/chm2pdf”, line 887, in
main(sys.argv)
File “/usr/bin/chm2pdf”, line 883, in main
convert_to_pdf(cfile, filename, outputfilename, options)
File “/usr/bin/chm2pdf”, line 180, in convert_to_pdf
objective_urls=get_objective_urls_list(filename)
File “/usr/bin/chm2pdf”, line 98, in get_objective_urls_list
flist=open(CHM2PDF_WORK_DIR+’/urlslist.txt’,'r’)
IOError: [Errno 2] No such file or directory: ‘/tmp/chm2pdf/work/McGraw-Hill – SCJP Sun Certified Programmer for Java 5 Study Guide (Exam 310-055) – 2006/urlslist.txt’
Marcus
11 Mar 08 at 3:33 am
there is a typo. should be –book
kindofabuzz
26 Mar 08 at 7:02 am
Markus
A trick can be to rename the source chm to something short, seems that chm2pdf does not handle all types of symbols in filename very well.
ie
McGraw-Hill – SCJP Sun Certified Programmer for Java 5 Study Guide (Exam 310-055) – 2006.chm
to
mcGraw.chm
Frode
11 Apr 08 at 1:46 am
Thank you so much. You saved me hours of work. Kyle
Kyle Janz
29 May 08 at 10:56 pm
I’m having a problem converting some O’Reily CHM files .
I’m using CHM2PDF 0.9.1 and getting this. I’ve tried it with several differnt CHM files. Any suggestions ? This is on a Fedora 8 box with 1GB of RAM.
Traceback (most recent call last):
File “/usr/bin/chm2pdf”, line 1111, in
main(sys.argv)
File “/usr/bin/chm2pdf”, line 1107, in main
convert_to_pdf(cfile, filename, outputfilename, options)
File “/usr/bin/chm2pdf”, line 326, in convert_to_pdf
objective_urls=get_objective_urls_list(filename)
File “/usr/bin/chm2pdf”, line 119, in get_objective_urls_list
urls_list.append(spline[5])
IndexError: list index out of range
Sir Geek
11 Jul 08 at 10:11 pm
Thank you very much
Layla & Zahra
13 Jul 08 at 11:11 am
@Marcus,@SirGeek, the problem its the long name of the file. Rename this to short-name.chm and try it again. it works for me.
There is another error, the parameter it’s not single ‘-’ it’s double.
its ‘–book’ not ‘-book’, see chm2pdf -h for more options.
Mort
2 Oct 08 at 9:28 pm
High All, I just tried this again, and now I am getting a different error
ERR002: Error: no pages generated! (did you remember to use webpage mode?
The command I used was
chm2pdf –book SHORTBOOK.chm
Any ideas ?
sirgeek
5 Oct 08 at 11:26 am
Hi to all first, second i convert tomorrow 1 .chm to .pdf with success so the correct command is:
chm2pdf –webpage nameofbook.chm
TomPapas
11 Oct 08 at 2:53 am
ok we have problem with the post program in this site. at webpage command need to put 2 – not only 1 like the linux help with 2 -. try it
TomPapas
11 Oct 08 at 2:55 am
I think TomPapas is trying to say this: as of the chm2pdf-0.9.1, you are now required to use two hyphens in the syntax. ex:
chm2pdf –book mychmdoc.chm
chm2pdf –webpage mychmdoc.chm
instead of the single:
chm2pdf -book mychmdoc.chm
which return the extended options list due to the syntax error.
uxp
21 Oct 08 at 1:07 am
O.o WordPress really has some interesting format issues with comments.
uxp
21 Oct 08 at 7:31 am
OK. I have found a solution. I did it as –webpage instead of –book and it created the PDF file properly.
At some point, the long filenames should be handled/escaped but that is a minor inconvenience to me.
Thanks !
Sir Geek
25 Oct 08 at 12:44 am
install this package and try
1> sudo apt-get install chm2pdf
then
2> chm2pdf else read man chm2pdf
Thanks,
Amaresh
Amaresh Das
3 Nov 08 at 4:55 pm
ravi@ravi:~$ cd Desktop
ravi@ravi:~/Desktop$ chm2pdf –webpage unix.chm
Usage:
/usr/bin/chm2pdf [options] input_filename [output_filename]
~~snipped by Harsh J~~
i am unable to get pdf file after using the above command i am getting the following can any one help how to change chm to pdf
ravikumardk
13 Jan 09 at 5:37 pm
I get the following error. I use version 0.9.1
Traceback (most recent call last):
File “/usr/bin/chm2pdf”, line 1098, in
main(sys.argv)
File “/usr/bin/chm2pdf”, line 1092, in main
convert_to_pdf(cfile, filename, outputfilename, options)
File “/usr/bin/chm2pdf”, line 318, in convert_to_pdf
objective_urls=get_objective_urls_list(filename)
File “/usr/bin/chm2pdf”, line 121, in get_objective_urls_list
urls_list.append(spline[5])
IndexError: list index out of range
I tried the –book option and –webpage option as well. It doesn’t work. Anybody faced this error and got around with it? Please help
Ramesh
30 Mar 09 at 3:33 am
Hi,
… Do you know any such script for reverse operation i.e. pdf->chm…
great find ! Worked quite well on my chm file
sherkhan
20 Apr 09 at 11:40 am
Thanks Harsh, a very neat program. The program and dependencies are all available in the Ubuntu repos and the program worked perfectly in Ubuntu 9.04
Surja
25 May 09 at 6:37 am
You might want to update your link, There is now a 9.1 version available.
Sir Geek
25 May 09 at 8:56 pm
Good work. Thanks!
Harry
3 Jun 09 at 3:43 pm
[...] with 26 comments [...]
CHM in PDF konvertieren | brain blogt... (jetzt auch!)
29 Jul 09 at 2:28 am
thank you Harsh
abhinav
30 Sep 09 at 11:44 pm
I get this error
cmcanulty@Gateway:~$ /home/chm2pdf-0.9.1
bash: /home/chm2pdf-0.9.1: No such file or directory
but the directory is there!
cmcanulty
6 Jun 10 at 6:22 am