It’s a year now since I bought Kindle for me. I have it still with me and frequently need to check PowerShell documentation. It led me to previous articles (1st and 2nd part) where I described in general, how to convert CHM file to MOBI. As I needed to automate it a bit, I created simple module for conversion process. Whole process is simple:

  1. Download ZIP file and unzip in to your module folder.
  2. Import module to your session (Import-Module chm2mobi).
  3. Run Convert-ChmToMobi <your_chm_file>.
  4. Copy MOBI to your e-reader and enjoy :)

To run it successfully, you need to have kindlegen installed on your computer and need to set alias kg to point to EXE file. On my PC I did it this way:

[11]: Get-Alias kg | ft -auto

CommandType Name Definition
----------- ---- ----------
Alias       kg   Dropbox:\Ruzne\KindleGen\kindlegen.exe

This is example output when generating file for PowerShell help topics (I recommend to use -Verbose parameter so you’ll see actual state of processing):

[16]: Convert-ChmToMobi .\PSHelp.chm

***********************************************
* Amazon.com kindlegen(Windows) V1.1 build 99 *
* A command line e-book compiler              *
* Copyright Amazon.com 2010                   *
***********************************************

opt version: try to minimize (default)
Info(prcgen): Added metadata dc:Title        "Title"
Info(prcgen): Added metadata dc:Date         "2011/09/11"
Info(prcgen): Added metadata dc:Creator      "moravec"
Info(prcgen): Added metadata dc:Subject      "Subject"
Info(prcgen): Added metadata dc:Description  "Description"
Info(prcgen): Parsing files  0000374
Warning(prcgen): <INPUT>, <SELECT> or <TEXTAREA> tag does no

Info(prcgen): Resolving hyperlinks
Info(prcgen): Resolving start reading location
Info(prcgen): Added metadata Start reading   "5098"
Info(prcgen): Computing UNICODE ranges used in the book
Info(prcgen): Found UNICODE range: Basic Latin [20..7E]
Info(prcgen): Found UNICODE range: General Punctuation - Windows 1252 [201C..201E]
Info(prcgen): Found UNICODE range: Latin-1 Supplement [A0..FF]
Info(prcgen): Building MOBI file, record count:   0001986
Info(prcgen): Compiling HTML Parser restart information
Info(prcgen): Final stats - text compressed to (in % of original size):  040.46%
Info(prcgen): The document identifier is: "Title"
Info(prcgen): The file format version is V6
Info(prcgen): Saving MOBI file
Info(prcgen): MOBI File successfully generated!

There are still some points I need to update or change. For example:

  • Easily add own Subject and Description.
  • Resolve problems when kindlegen alias not presented.
  • Add more control over generating files – generate only some files.
  • Not show kindlegen output when not requested.
  • Remove files at the end when requested.
You can check Get-Help Convert-ChmToMobi if you need more info. Note: Time of file processing it really dependent on your HW. On my PC it tool almost 90 minutes to generate MOBI for Lync server, but on Tom’s (see below) it was about three minutes.
I’d like to send big thanks Tom Arbuthnot (@tomarbuthnot) for initial testing of this module.