i try to convert html string to docx file.
its working ok but when i try to enter hebrew words and rtl it its not working good.
My code:
- Code: Select all
public static void main(String[] args) throws Exception
{
String html = "<html><head><title>Import me</title></head><body style=\"text-align: right;\"><table border=\"1\"><tbody><tr><td width=\"100\">מס'</td><td>נסיון:</td><td width=\"200\">לורם איפסום דולור סיט אמט, קונסקטורר אדיפיסינג אלית ושבעגט ליבם סולגק. בראיט</td></tr></tbody></table></body></html>";
docx4j(html);
}
private static void docx4j(String html) throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
ndp.unmarshalDefaultNumbering();
BooleanDefaultTrue trueVar = new BooleanDefaultTrue();
XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
List l = XHTMLImporter.convert( html, null);
Tbl t = (Tbl) l.get(0);
t.getTblPr().setBidiVisual(trueVar);
l.set(0, t);
wordMLPackage.getMainDocumentPart().getContent().addAll(l);
System.out.println(XmlUtils.marshaltoString(wordMLPackage
.getMainDocumentPart().getJaxbElement(), true, true));
wordMLPackage.save(new java.io.File("C:\\test\\sample.docx"));
System.out.println("done");
}
its look like:
but its need to look like:
the ' and : need to be in the left side and not right side of the text.
how can i set all the document rtl. ?