Docx Template(with Freemarker placeholders) to XHTML

919 views
Skip to first unread message

rama

unread,
Nov 12, 2013, 11:08:51 AM11/12/13
to xdocr...@googlegroups.com
Hi,

I am using Docx Template(with Freemarker placeholders) to XHTML conversion. The conversion is backed by a Bean (data model). Everything works as expected but i wan to let user mark some placeholders in Docx Template
as Editable in output XHTML file. This means for some fields i dont want to replace the Freemarker placeholder with the value from Bean but with a JSF input tag like <h:inputText value="#{Bean.propertyName}">. So the generated XHTML would render the edit box to user for certain fields.

I have no idea, Is it something that is achievable (through configuration or minor code extensions) or it is a requirement that is not achievable at all? 

Regards,

Angelo zerr

unread,
Nov 12, 2013, 11:27:18 AM11/12/13
to xdocr...@googlegroups.com
Hi rama,

I have never done that, so it's difficult to tell you if it's possible. To do that, there are 2 options : 

1) generate a docx template with  <h:inputText value="#{Bean.propertyName}"> (to do that you must use SyntaxKind.NoEscape (like HTML text styling  https://code.google.com/p/xdocreport/wiki/DocxReportingJavaMainHTMLTextStyling)
2) convert the docx as html.

But I'm afraid that POI crashes if it find some XML contents which doesn't know.

The second alternative is to do like this : 

1) generate a docx with #{Bean.propertyName}"

But I don't know if it works.

Tell me if you can achieve that.

Regards Angelo


2013/11/12 rama <inform...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "xdocreport" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xdocreport+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

rama

unread,
Nov 12, 2013, 11:56:26 AM11/12/13
to xdocr...@googlegroups.com
Thank Angelo, i would try that. The problem is that we have to use the same docx template for pdf conversion (which is readonly) and if i use JSF syntax in docx template then nothing would be populate in generated pdf.

rama

unread,
Nov 13, 2013, 4:32:54 AM11/13/13
to xdocr...@googlegroups.com

I am using IXDocReport.convert(...) for conversion not directly the converter classes, is there any guideline how to extend this and should i have to tweak myself?

Angelo zerr

unread,
Nov 13, 2013, 6:16:13 AM11/13/13
to xdocr...@googlegroups.com
Hi rama,

There no docs about that. 

I have attached some Java classes which shows you how to extend the XHTMLConverter (it's a little complex, perhaps it should be better to modify the converter to extend it more easily).
XDocReport uses SPI provider to register their converter (to use it with report.convert). The SPI META-INF/services/fr.opensagres.xdocreport.converter.discovery.IConverterDiscovery (which must be hosts in your classpath) is used to register your own converter : 

-----------------------------------------------------------------------------------------
myconverter.discovery.MyXWPF2XHTMLConverterDiscovery
-----------------------------------------------------------------------------------------

The MyXWPF2XHTMLConverterDiscovery#getVia() returns "MyConverter".

So after you can do :

Options options = Options.getTo(ConverterTypeTo.XHTML).via("MyConverter");
report
.convert(context, options, out);

MyXWPF2XHTMLConverterDiscovery uses MyXHTMLConverter which uses MySimpleContentHandler the SAX Handler that you must modify.

Hope it will help you.


2013/11/13 rama <inform...@gmail.com>
mysrc.zip

rama

unread,
Nov 14, 2013, 6:03:16 AM11/14/13
to xdocr...@googlegroups.com
Thanks Angelo. After making some tests with conversion to xhtml i found, The results of the conversion seems promising BUT unfortunately no Table Border support and image handling. 

Angelo zerr

unread,
Nov 14, 2013, 6:08:17 AM11/14/13
to xdocr...@googlegroups.com



2013/11/14 rama <inform...@gmail.com>

Thanks Angelo. After making some tests with conversion to xhtml i found, The results of the conversion seems promising

That's cool
 
BUT unfortunately no Table Border support and image handling. 

As I said you, table border is in my scope (but when?). Image works but I have not spoken about that in the doc. See sample at https://code.google.com/p/xdocreport/source/browse/thirdparties-extension/org.apache.poi.xwpf.converter.xhtml/src/test/java/org/apache/poi/xwpf/converter/xhtml/XHTMLConverterTestCase.java

I think too the XHTMLConverter should be customized with custom SAX Handler to avoid developping a new converter like I hav eexplained you.

If you wish, I can do that quicly.

Regards Angelo

rama

unread,
Nov 14, 2013, 6:33:51 AM11/14/13
to xdocr...@googlegroups.com
Thanks Angelo,

>>If you wish, I can do that quicly.
That would be great :)

Angelo zerr

unread,
Nov 14, 2013, 8:36:23 AM11/14/13
to xdocr...@googlegroups.com


2013/11/14 rama <inform...@gmail.com>

--

rama

unread,
Nov 14, 2013, 9:56:58 AM11/14/13
to xdocr...@googlegroups.com
Thanks Angelo, is there any quick (perhaps dirty) way to show table borders? I have a use case where i need to display the border of one table.


On Tuesday, November 12, 2013 5:08:51 PM UTC+1, rama wrote:

Angelo zerr

unread,
Nov 14, 2013, 9:58:26 AM11/14/13
to xdocr...@googlegroups.com
If you customize the SAX Content Handler, you could perhaps add with hard code the border?


2013/11/14 rama <inform...@gmail.com>

--

rama

unread,
Nov 14, 2013, 9:59:10 AM11/14/13
to xdocr...@googlegroups.com
Also, the method characters() in SimepleContentHandler is final, so cant override it.


On Tuesday, November 12, 2013 5:08:51 PM UTC+1, rama wrote:

Angelo zerr

unread,
Nov 14, 2013, 10:47:42 AM11/14/13
to xdocr...@googlegroups.com
I have commited https://code.google.com/p/xdocreport/source/detail?r=bc7cc80bcd22b8701c52881ffb381cc6620b5d0b to override the flushCharacters (and not the character method).


2013/11/14 rama <inform...@gmail.com>

--

rama

unread,
Nov 27, 2013, 10:55:54 AM11/27/13
to xdocr...@googlegroups.com
Hi,

>>I have commited https://code.google.com/p/xdocreport/source/detail?r=bc7cc80bcd22b8701c52881ffb381cc6620b5d0b to override the flushCharacters (and not the character method).
I have maven dependency to 1.0.4-SNAPSHOT but could not see your changes. Do i have right dependency there?

Regards,

On Tuesday, November 12, 2013 5:08:51 PM UTC+1, rama wrote:

Angelo zerr

unread,
Nov 27, 2013, 4:47:55 PM11/27/13
to xdocr...@googlegroups.com
Build was not done. I have started it. See at https://opensagres.ci.cloudbees.com/job/xdocreport/


2013/11/27 rama <inform...@gmail.com>

--
Reply all
Reply to author
Forward
0 new messages