Page 1 of 1

Add style to HTML

PostPosted: Tue Mar 30, 2010 10:37 pm
by reddd
Hi again,
i already posted on this forum talking about inserting more than one image in my docx.
Now the problem is to give a style, a paragraph style, to the HTML i got from my application:
using poor words, i need to define a style into the template.docx, and this style have to be applied to the HTML i got from my Tiny editor used in the web application. i don't know how to proceed :? , 'cause when i merge the template.docx with my dynamic data, no style is manteined.

thanks in advance for help!

Reddd

Re: Add style to HTML

PostPosted: Wed Mar 31, 2010 8:27 pm
by jason
You might need to explain in a little more detail what you are trying to do.

However, if your template.docx includes a paragraph which uses your style, you could use docx4j to output that docx as HTML (see the Getting Started Guide).

If you view the source of the HTML, you will see the generated CSS.

You could copy/paste this CSS.

Alternatively, you can look at the docx4j source code to see how it generates CSS and copy this.

NG2 generates and applies a hierarchy of CSS definitions which match the Word style hierarchy. iirc, the original HTML exporter creates consolidated non-hierarchical CSS. That might suit your needs better (but is deprecated).

Re: Add style to HTML

PostPosted: Thu Apr 01, 2010 7:32 pm
by reddd
Hi jason,
thanks for the answer, but maybe i didn't explain my problem in a good way.

I add HTML to the docx using these instructions:


String htmlStr = “<html><head></head><body><span>MY TEXT MY TEXT MY TEXT</span></body></html>”;
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(fileOut);
MainDocumentPart main = wordMLPackage.getMainDocumentPart();

AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/hw"+countCap+".html") );
afiPart.setBinaryData(htmlStr.getBytes());
afiPart.setContentType(new ContentType("text/html"));

Relationship altChunkRel = main.addTargetPart(afiPart);
CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
ac.setId(altChunkRel.getId());

main.addObject(ac);


At this point, i want to assign a particular style, which is defined into the docx, to my HTML...
but as i told you in the first post, i am not able to do this.


thanks again for your help and patience

Reddd

Re: Add style to HTML

PostPosted: Mon Apr 05, 2010 12:02 pm
by jason
Hi Reddd

I think my suggestions stand.

I haven't used the OpenXML altChunk stuff myself, but I'd guess that if you are using an HTML chunk, you can style it via CSS. So that means including the CSS in a <style> tag in the altChunk (or apparently, using an MHT file, an including a .css in it).

So if you are including the CSS in an *HTML* <style> tag in the altChunk, the question becomes, how do you create that from an existing Word style?

And my answer to that is in my previous post :-)

May I ask why you are using altChunk? If you need to change how the HTML is styled, might it not be easier to convert your HTML to OpenXML?

cheers .. Jason

Re: Add style to HTML

PostPosted: Thu May 13, 2010 6:57 am
by vikrant
Hi Redd,

I am curious to know if you were able to apply css style to the embedded html ? Please let me know how you were able to achieve this, I have a similar problem, see

viewtopic.php?f=6&t=313