I've different docx files (created in Word and filled with XdocReport). Two of these files must be generated as A5 PDFs (so, that the printer automaticaly will choose the correct tray). A5 isn't yet supported in docx4J, so I wrote following code:
- Code: Select all
void setPageSize(WordprocessingMLPackage wordMLPackage, String sz, boolean landscape){
Body body = wordMLPackage.getMainDocumentPart().getJaxbElement().getBody();
PgSz pgsz = body.getSectPr().getPgSz();
if (sz.equals(A5)) {
pgsz.setCode(BigInteger.valueOf(10)); // ??? A3 is 8 - A4 is 9 - may be 10 for A5
if (landscape) {
pgsz.setOrient(STPageOrientation.LANDSCAPE);
pgsz.setW(BigInteger.valueOf(11907));
pgsz.setH(BigInteger.valueOf(8419));
} else {
pgsz.setW(BigInteger.valueOf(8419));
pgsz.setH(BigInteger.valueOf(11907));
}
}
}
And the calling method:
- Code: Select all
public static byte[] convertDOCXToPDF(byte[] docdata)
{
byte[] result = null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
try
{
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new ByteArrayInputStream(docdata));
setPageSize(wordMLPackage, "A5", false);
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(wordMLPackage);
Docx4J.toFO(foSettings, out, Docx4J.FLAG_NONE);
result = out.toByteArray();
return result;
}
catch (Docx4JException e)....
}
The result is still an A4 PDF
The docx file is in format A5 - best would be to read the size, orientation and margins from the inputdata, but that seems not to be supported?
any help would be nice
thanx
Andreas