Page 1 of 1

Docx4jProperties is not working

PostPosted: Wed May 04, 2022 10:19 pm
by mithilesh.jha
I am setting below properties in my code while converting from xhtml to docx, but these are not getting reflected in the output docx file.

Docx4jProperties.setProperty("docx4j.PageSize", "A4");
Docx4jProperties.setProperty("docx4j.FontSize", "10.5");
Docx4jProperties.setProperty("docx4j.PageMargins", "WIDE");
Docx4jProperties.setProperty("docx4j.PageOrientationLandscape", "true");

Can you please help here.

Re: Docx4jProperties is not working

PostPosted: Mon May 16, 2022 9:33 am
by jason
mithilesh.jha wrote:Docx4jProperties.setProperty("docx4j.PageSize", "A4");
Docx4jProperties.setProperty("docx4j.PageMargins", "WIDE");
Docx4jProperties.setProperty("docx4j.PageOrientationLandscape", "true");


would be used in sectPr elements, for example:

[xml
<w:sectPr>
<w:pgSz w:w="16839" w:h="11907" w:orient="landscape" w:code="9"/>
<w:pgMar w:top="1440" w:right="2880" w:bottom="1440" w:left="2880"/>
</w:sectPr>
[/xml]

WordprocessingMLPackage.createPackage() does that.

If your sectPr elements already exist or you create them in some other way, then the above properties may be ignored.

Regarding docx4j.FontSize, where did you come up with that from? Its not a recognised property.

By the way, it is more usual to have a docx4j.properties file on your classpath, than to set properties programmatically.