Hi Jason
Thank you for the response .But i still see the issue. here is the code
- Code: Select all
public static void main(String[] a){
try{
WordprocessingMLPackage mlPackage = WordprocessingMLPackage.createPackage();
ArrayList<DocSection> sec=new ArrayList();
sec.add(new DocSection("<html><p>hi</p></html>","portrait"));
sec.add(new DocSection("<html><p>hi</p></html>","landscape"));
sec.add(new DocSection("<html><p>hi</p></html>","portrait"));
java.util.Iterator<DocSection> itr = sec.iterator();
while(itr.hasNext()){
DocSection temp=(DocSection) itr.next();
SectPr sectPr=null;
ObjectFactory objectFactory = new ObjectFactory();
sectPr = objectFactory.createSectPr();
PgSz landscape = new PgSz();
landscape.setH(BigInteger.valueOf(11906));
landscape.setW(BigInteger.valueOf(16383));
if("landscape".equalsIgnoreCase(temp.orientation)){
/*sectPr = (org.docx4j.wml.SectPr)org.docx4j.XmlUtils.unmarshalString("<w:sectPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">"
+ "<w:pgSz w:w=\"16839\" w:h=\"11907\" w:orient=\""+temp.orientation+"\"/>"
+ "</w:sectPr>");*/
landscape.setOrient(STPageOrientation.LANDSCAPE);
}else{
/*sectPr = (org.docx4j.wml.SectPr)org.docx4j.XmlUtils.unmarshalString("<w:sectPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">"
+ "<w:pgSz w:w=\"16839\" w:h=\"11907\" />" + "</w:sectPr>");*/
landscape.setOrient(STPageOrientation.PORTRAIT);
}
sectPr.setPgSz(landscape);
P p = objectFactory.createP();
PPr createPPr = objectFactory.createPPr();
createPPr.setSectPr(sectPr);
p.setPPr(createPPr);
mlPackage.getMainDocumentPart().addAltChunk(
org.docx4j.openpackaging.parts.WordprocessingML.AltChunkType.Html,
temp.htm.toString().getBytes());
org.docx4j.wml.Br objBr = new org.docx4j.wml.Br();
objBr.setType(org.docx4j.wml.STBrType.PAGE);
//mlPackage.getMainDocumentPart().addObject(objBr);
mlPackage.getMainDocumentPart().addObject(p);
}
FileOutputStream out = new FileOutputStream("test.docx");
mlPackage.save(out);
}catch(Exception e){
e.printStackTrace();
}
}
DocSection is wrapper class to hold html chunks and page orientation. my requirement is to display each html in specified orientation. And here is the generated docx. I could not understand on generated out put. What i understood from generated document.xml from web app for similar docx uploaded , after each chunk there should be w:p\W:PPr\W.sectPR. But last chunk dont have ppr instead there is sectpr at the end before body. Tried all these but do not help me. Could you please check and let me know where i am going wrong.
Also i dont understand why an empty page generated at the end