4

I need to set landscape to some pages of a document. I tried this code:

    SectPr sectionLandscape = objectFactory.createSectPr();

String rsidR = sectionLandscape.getRsidR();     

SectPr sectionPortrait = objectFactory.createSectPr();
sectionPortrait.setRsidR(rsidR);
sectionPortrait.setRsidSect(rsidR);    

PgSz landscape = new PgSz();
landscape.setOrient(STPageOrientation.LANDSCAPE);
landscape.setH(BigInteger.valueOf(11906));
landscape.setW(BigInteger.valueOf(16383));       

sectionLandscape.setPgSz(landscape);

mdp.addObject(sectionLandscape);

It creates this xml code:

<w:sectPr>
    <w:pgSz w:w="16383" w:orient="landscape" w:h="11906"/>
</w:sectPr>

And after of the Section tag have the text and the table that i need inside landscape page. With Word 2007/2010 i only see the portrait page and in editing mode of the page I can see the page selected as landscape.

https://i.stack.imgur.com/HHuGB.png

phew
  • 55
  • 7

1 Answers1

2

The sectPr should be in a w:p/w:pPr after the content which it is to appear in landscape orientation.

You need sectPr specifying portrait before that content.

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
  • Thanks! It works, I tested with this code and works: SectPr sectionLandscape = objectFactory.createSectPr(); PgSz landscape = new PgSz(); landscape.setOrient(STPageOrientation.LANDSCAPE); landscape.setH(BigInteger.valueOf(11906)); landscape.setW(BigInteger.valueOf(16383)); sectionLandscape.setPgSz(landscape); org.docx4j.wml.P p = objectFactory.createP(); PPr createPPr = objectFactory.createPPr(); createPPr.setSectPr(sectionLandscape); p.setPPr(createPPr); mdp.addObject(p); – phew Feb 21 '13 at 01:29