Using Safari on iPhone to read CHM file
iPhone is a fancy toy with a lot of power but Apple deliberately locks a lot of the potential power. One thing I like to do on an iPhone is to be able to read CHM files. As a weekend project, I setup the tool chain for iPhone following the instructions. Then, I grabbed the source code of chmlib. With some minor modification, I was able to compile the chmlib as an iPhone binary library. That was very encouraging.
This provides a convenient way to make iPhone as a CHM reader. In the chmlib source code distribution, there is an example program that runs as a http-server that serves the content of a CHM as standard web page. The “mobileSafari” has no problem to render the results, but the fonts are usually too small to read and the text is typically rendered too wide such that a lot horizontal scrolling becomes annoyingly necessary.
I decided to combine some python code with the chm_http server from the chmlib source code. I modified the source code of chm_http so it can call python code to modify the HTML code in the CHM file, replacing the original CSS with new setting for reading on small screen. Furthermore, I found it was tedious to start the chm_http from a terminal every time when you want to read a different book. I wrote another small python script that can scan a directory and find all CHM files in the directory to output an index html page. At the end, I was able to use the mobileSafari pointing to the index page and select the book I want to read. The “chm_http” server would start automatically to get the book I like to read.
If you are interested in reading CHM on your iPhone. Get this iphoneCHM.tgz (the file would be upload soon). Copy the “chm_http2“, “rewriteHTML.py“, and “CHMServer” to “/usr/local/bin/” in your iPhone. Change the permission of these files such that you can run all of them. Put some chm files in /var/root/Media/CHM_Ebooks/. Open a terminal in the iPhone or ssh into the iPhone to run “CHMServer”. After that, ask the Safari to open this URL http://127.0.0.1:8000. You should see the links to the CHM files. You can now click on any of them and enjoy a nice reading time.
Technorati Tags: hacking, programming
November 3rd, 2007 at 2:17 am
“Open a terminal in the iPhone or ssh into the iPhone to run “CHMServer”.”
can you please provide the steps for the above
thanks
(no programming knowledge)
November 11th, 2007 at 4:52 pm
Can you seperate the files for the ones who don’t have mac ?
Unzipping the tgz fine under windows brings only one file iphoneCHM which i assume to be a directory which includes the mentioned files.
November 11th, 2007 at 5:52 pm
Thanks for this great looking method. I have a problem using it correctly and hope that even after 2 months you are still around here. 127.0.0.1:8000 opens a list of my CHM files and their contents, but after proceeding on any of the content links a “404 file not found” errors occurs. On terminal CHMServer says: “kill: not enough arguments”. What could be the reason? I’m using 1.1.1. Thanks for any help!
November 17th, 2007 at 7:40 am
Hello,
I was so excited to try to read CHMs on my iPhone as you guided. However, as I run CHMServer in Term-vt100, it says “kill: not enough arguments”. Am I missing anything?
Thanks so much.
Dave
November 17th, 2007 at 8:43 pm
When you see “kill: not enough arguments”, it means that one of the script can not find the process that serve CHMs. Mostly likely, the permission for the program “chm_http2″ is not set correctly, or it is not in the right place. The script and “chm_http2″ should be in “/usr/local/bin”. If you installed the code under “/usr/local/bin”, the code should run fine if the UNIX permission setting is correctly. You can check the permission by “ls -l chm_http2″. You should see “-rwxr-xr-x”, if you do not see “x”, do “chmod a+x chm_http2″ using Terminal.app (or, better, ssh into your iphone) under “/usr/local/bin”.
I will try to write some step by step instruction if I finally get a little more free time working on iPhone hacking.
Thanks for your interesting on the code and sorry for not responding fast. I just move to a new place and there are too many other things needed to be fixed.
November 17th, 2007 at 9:12 pm
I changed permission of all 3 files to 755 but didn’t help.
I dont know about Python programming but after some Googling, I changed the second line from bottom of CHMServer (os.system …) to:
print “Running…” then it worked but I think there are errors. I got to Safari via 127.0.0.1:8000 and the CHMs showed up, but their content is a little bit messy/broken. I am not sure if it is the way it is supposed to be.
Please keep us updated.
Dave
November 17th, 2007 at 11:41 pm
Dave:
Can you check if you have “grep” and “cut” in your iphone? If not, you will have to install the BSD pack for iphone. One thing you can try is to start chm_http2 manually from a ssh connection using
/usr/local/bin/chm_http2 –port=8888 –bind=127.0.0.1 /var/root/Media/CHM_Ebooks/yourCHMFile.chm
Replace “yourCHMFile.chm” with the real CHM file name. That will start the chm http server at port 8888. After that, try to point Safari to http://127.0.0.1:8888 to see if you can see your CHM file.
The default output of CHM could be messy. The chm_http2 is a bare bone chm parser. I set it to display the every individual html file in the chm file with a “home” link on the top. The home link typically gives the table of content, but it could give you something else depending on how the CHM is compiled.
November 28th, 2007 at 2:12 pm
Please consider creating an AppTap package. Even at this stage (using Safari and local http server), until someone creates a native reader, it would be a much better experience if the installation process is simplified. I’m not sure if you can check for certain port availability in AppTap script, but even if it can’t, just display a message/notice. And another thing is to automatically create/add a bookmark in safari pointing to that http server.
April 5th, 2008 at 7:09 am
Awesome dude!
Works like a charm. No problem getting it to work at all, but of course as gtanuel said an AppTap package would be even better. Truly nice job though.
April 14th, 2008 at 6:58 pm
I changed permission of all 3 files to 755.
When I tried to run CHMServer in Term-vt100, it said interpretation error and
Python is not exist. I am running 1.1.4 and used iPlus.
Is there any work around solution on this?
Thanks / Henry
April 14th, 2008 at 7:59 pm
Henry:
Thanks for leaving a message. Unfortunately, the python is needed to make it possible to navigate the pages and make the fonts bigger for iphone. It is just tedious to do that in C so python is absolutely needed. The only work around is to install python through installer.
–orcas
April 16th, 2008 at 6:58 am
Hi Orcas,
Thanks for the advise. I install python.
now I pass the error but I got the same “kill: not enough arguments” msg as mentioned from the top. I did change all file to 777 and double checked with ls -l.
I also hv “grep” and “cut” . So I have no clue what is missing this time.
Any suggestion?
Thanks / Henry
April 23rd, 2008 at 8:03 pm
I have read chms using two alternative ways:
1.- Install a web server (in my case I used lighttpd) and uncompress the chm files under the web server directory and voila, just go to localhost and open them up
2.- Check the following link:
http://www.modmyifone.com/forums/showthread.php?t=29842
Good luck!
April 24th, 2008 at 8:16 am
Thanks.
For your method
1) how can I uncompress CHM on iphone (what unix command and format should I type in terminal?) and where is the web server directory in iphone? is it var/mobile/Sites?
2) I tried this tool too. I can run it and see the CHM file in the list of the app but when I select the CHM it go back to springboard. will u have any clue for this too?
Thanks lot.
April 24th, 2008 at 4:07 pm
Henry,
Well, to uncompress the CHM files, I use 7-Zip and then I upload the uncompressed result to the ipod.
With respect to the tool, go to /var/Applications/MobileCHM.app/
and then type:
chmod +x *
chmod +s MobileCHM
chmod +s clit
That should make it work.
By the way, you can combine this tool and lighttpd. However, this seems to use extra disk space as the CMH reader uncompresses the CHM on the web server pages directory… The benefit is that reading the CHM file with safari is much better than with the embedded browser they provide.
April 24th, 2008 at 10:55 pm
Hey thanks a lot. It works wonderfully well for yr 1st method.
Now I dont need to consider the 2nd way.
Cheers