Page 1 of 1

Need to use 'o.table footnote' para style when insering HTML

PostPosted: Fri Apr 04, 2014 1:19 am
by tarik.habibullah
Hi,

I am using docx4j API's to generate a docx. I am programmatically inserting HTML code in the docx at a given index.
The issue which I am facing is that I want to use 'o.table footnote' style for the paragraph which contains the HTML.

Code: Select all
Relationship altChunkRel1 =  documentTemplate.getMainDocumentPart().addTargetPart(DocumentUtil.showHtml((new String(section.getSectionNotes().toCharArray())), index));                                                                                                   
CTAltChunk ac1 = Context.getWmlObjectFactory().createCTAltChunk();
ac1.setId(altChunkRel1.getId());
documentTemplate.getMainDocumentPart().getContent().add(index, ac1);

and method DocumentUtil.showHtml is as follows
Code: Select all
public static AlternativeFormatInputPart showHtml(String notes, int index) {
        try {
            StringBuilder htmlComment = new StringBuilder();
            htmlComment.append("<html><span style=\"font-family: Arial Narrow;font-size : 7pt;\">");
            notes =replaceSpecialChars(notes);           
            htmlComment.append(notes);
            htmlComment.append("</span></html>");
            AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/hw" + index + ".html"));
            afiPart.setBinaryData(htmlComment.toString().getBytes("UTF-8"));           
            afiPart.setContentType(new ContentType("text/html"));
            return afiPart;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

A styled paragraph created programmatically

<w:p w:rsidR="001A6852" w:rsidRDefault="001A6852">
<w:pPr>
<w:pStyle w:val="otablefootnote"/>
</w:pPr>
</w:p>

A HTML content converted into docx format

<w:p w:rsidR="001A6852" w:rsidRDefault="001A6852">
<w:pPr>
<w:divId w:val="1629387063"/>
</w:pPr>
<w:r>
<w:rPr>
<w:sz w:val="14"/>
<w:szCs w:val="14"/>
</w:rPr>
<w:t>Section Notes : Data</w:t>
</w:r>
</w:p>

Please help.

Thanks
Tarique

Re: Need to use 'o.table footnote' para style when insering

PostPosted: Fri Apr 04, 2014 10:15 am
by jason
You'll have more control if you have docx4j do the XHTML to docx content conversion.

Still, at present that doesn't support arbitrary @class val to style name mapping, though there has been recent discussion about adding this. Can you attach @class="otablefootnote" in your source XHTML?

Re: Need to use 'o.table footnote' para style when insering

PostPosted: Tue Apr 08, 2014 1:28 am
by tarik.habibullah
I tried using class="otablefootnote" by surrounding a span tag in the source HTML. it didn't work.
Please suggest any other alternative if available?

Re: Need to use 'o.table footnote' para style when insering

PostPosted: Tue Apr 08, 2014 8:00 am
by jason
"it didn't work" is difficult to diagnose!

What was your input XHTML, your Java code, and the resulting Open XML?

Were you adding it to a docx in which that style was defined?

Re: Need to use 'o.table footnote' para style when insering

PostPosted: Wed Apr 09, 2014 1:30 am
by tarik.habibullah
surrounding the html content by <p class="otablefootnote" > makes it work.

Thanks.