Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Convert doc/docx file to chm file

Tags:

java

docx

doc

chm

I have an idea of converting Word document(.doc/.docx) files to Help file(.chm) format. I want to use Java for the conversion of files. My formula is simple. To make the Table of Contents page and other links in word document, as package explorer or File explorer and make the user navigation simpler, faster and easy to navigate among the pages in the document.

So, My Question is :

Are there any native libraries in java that can be imported and used for File Conversion?

Please share your ideas to implement the above concept.

like image 878
Avadhani Y Avatar asked May 02 '12 11:05

Avadhani Y


1 Answers

Its a pretty difficult task to be done in Java. But you can still do it if you install Microsoft HTML Help Workshop.

  1. First you can extract the text of the Word documents via Apache POI and then output them as HTML documents to a temporary directory.
  2. Next you need to create a HHP file. It should be fairly easy to create as it is a text file. Just follow the specifications given here
  3. Then you should have a corresponding HHC file as well. Its a simple HTML document in the following format:

    <html>
    <head>
    </head>
    <body>
    <ul>
    <li><object type="text/sitemap">
    <param name="Name" value="Foo Directory">
    <param name="Local" value="BarDirectory/index.htm">
    <param name="ImageNumber" value="1">
    </object></li>
    <ul>
    <li><object type="text/sitemap">
    <param name="Name" value="Topic1">
    <param name="Local" value="BarDirectory/Bar.htm">
    <param name="ImageNumber" value="11">
    </object></li>
    <li><object type="text/sitemap">
    <param name="Name" value="Topic1">
    <param name="Local" value="BarDirectory/Foo.htm">
    <param name="ImageNumber" value="11">
    </object></li>
    </ul>
    </ul>
    </body>
    </html>
    

    Similarly look up the structure for a HHK file.

  4. Once you are done you can execute hhc.exe <inputfile.hhp> from Java. That should do the job.
like image 145
Sankha Narayan Guria Avatar answered Sep 29 '22 01:09

Sankha Narayan Guria