Page 1 of 1

Import XHTML to Docx: Convert Headings to Bookmark

PostPosted: Tue Aug 26, 2014 2:54 pm
by coolrb
Hello:
I am converting XHTML to docx. The inner links do not work. Inner links point to different sections and also images. External links do work. I found that the problem with heading tags and they should be converted to Bookmarks like the way anchor tags with name attribute(<a name='bookmark'>Text</a>) gets converted. Any suggestion?

Re: Import XHTML to Docx: Inner Hyperlinks does not work

PostPosted: Wed Aug 27, 2014 4:40 am
by coolrb
I came across this posthttp://www.docx4java.org/forums/xhtml-import-f28/create-bookmarks-from-xhtml-t1815.html#p6193 and looked at suggestion by Jason. The problem I am facing to convert Headings to appropriate Bookmarks. I did a shortcut by modifying headings e.g.
Code: Select all
Elements h2s = doc.select("h2[class=Head2]");
        for( Element urlElement : h2s )
        {
           String id = urlElement.attr("id");
          urlElement.attr("name", id);
          urlElement.html("<a name="+id+">"+urlElement.text()+"</a>");
        }

And then all links started working. But at the same time headings2 turned into links with color change and also same reflected in TOC. Are there any other ways I can convert Headings/Figures into book marks?

Re: Import XHTML to Docx: Convert Headings to Bookmark

PostPosted: Thu Aug 28, 2014 6:18 pm
by coolrb
As this is very crucial for go/nogo, I would appreciate for any clue/suggestion to modify code to take care headings. Let me add it here that currently we are using XHTML->XSLT->XSL-FO->Apache-Fo->PDF/Word workflow. As its quite expensive in terms of resources, I am finding alternate way.

Re: Import XHTML to Docx: Convert Headings to Bookmark

PostPosted: Fri Aug 29, 2014 7:51 pm
by jason
You can try http://www.docx4java.org/docx4j/docx4j- ... 140829.jar

That is a post 3.2.0 nightly build, probably best used with docx4j 3.2.0

With that, an internal link (<a href="#id1>some link</a>) to an element with an id, such as <h1 id="id1">, ought to convert to a Word hyperlink.

Alternatively, instead of @id, you can wrap the element in <a>, with @name="id1".

Re: Import XHTML to Docx: Convert Headings to Bookmark

PostPosted: Sat Aug 30, 2014 5:03 am
by coolrb
Thanks Jason. It worked. I think I have now comfortably move to docx4j. The only issue now I have is TOC generation. I am again going to work on enterprise version. I really want to thank team docx4j for such a wonderful library especially simplicity of implementation.