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.
#1 by aaron on March 8th, 2009
Quote
hey i was trying to compile chmlib against iphone arm and i was having many errors.. i guess i dont know the right defines? what did you have to set to make it work? and do you happen to have the .a i could use?
#2 by Kit on July 17th, 2009
Quote
Thanks a lot for your sharing.
Just some suggestion to your sharing.
insert a file called “com.chmserver.plist” in “/Library/LaunchDaemons/”
inside com.chmserver.plist
Label
com.chmserver
OnDemand
Program
/usr/local/bin/CHMServer
StandardErrorPath
/dev/null
#3 by Kit on July 17th, 2009
Quote
Sorry, this is inside the com.chmserver.plist
Label
com.chmserver
OnDemand
Program
/usr/local/bin/CHMServer
StandardErrorPath
/dev/null
#4 by Jason Chin on July 23rd, 2009
Quote
Thanks for pointing this out. I seldom jb my iphone recently, so I no longer know what the underlying OS looks like now. Anyway, Your information should help a lot of JBers.