use of org.docx4j.wml.SectPr.PgSz in project docx4j-template by vindell.
the class Docx4j_Helper method testDocx4jSetPageSize.
public void testDocx4jSetPageSize() throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
String titleStr = "静夜思 李白";
String str = "床前明月光,疑似地上霜。";
String str2 = "举头望明月,低头思故乡。";
P p = Docx4j_Helper.factory.createP();
String rprStr = "<w:rPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:rFonts w:hint=\"eastAsia\" w:ascii=\"Times New Roman\" w:hAnsi=\"Times New Roman\" w:eastAsia=\"宋体\"/><w:b/><w:color w:val=\"333333\"/><w:sz w:val=\"32\"/><w:szCs w:val=\"32\"/></w:rPr>";
RPr rpr = (RPr) XmlUtils.unmarshalString(rprStr);
setParagraphContent(p, rpr, titleStr);
mdp.addObject(p);
p = Docx4j_Helper.factory.createP();
setParagraphContent(p, rpr, str);
mdp.addObject(p);
p = Docx4j_Helper.factory.createP();
PPr pPr = Docx4j_Helper.factory.createPPr();
// 设置文字方向
SectPr sectPr = Docx4j_Helper.factory.createSectPr();
TextDirection textDirect = Docx4j_Helper.factory.createTextDirection();
// 文字方向:垂直方向从右往左
textDirect.setVal("tbRl");
sectPr.setTextDirection(textDirect);
Type sectType = Docx4j_Helper.factory.createSectPrType();
// 下一页
sectType.setVal("nextPage");
sectPr.setType(sectType);
// 设置页面大小
PgSz pgSz = Docx4j_Helper.factory.createSectPrPgSz();
pgSz.setW(new BigInteger("8335"));
pgSz.setH(new BigInteger("11850"));
sectPr.setPgSz(pgSz);
pPr.setSectPr(sectPr);
p.setPPr(pPr);
setParagraphContent(p, rpr, str2);
mdp.addObject(p);
p = createParagraphWithHAlign();
setParagraphContent(p, rpr, titleStr);
mdp.addObject(p);
p = createParagraphWithHAlign();
setParagraphContent(p, rpr, str);
mdp.addObject(p);
p = createParagraphWithHAlign();
setParagraphContent(p, rpr, str2);
mdp.addObject(p);
// Docx4j_Helper.saveWordPackage(wordMLPackage, outputfilepath);
}
use of org.docx4j.wml.SectPr.PgSz in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method setDocumentSize.
/**
* @Description: 设置页面大小及纸张方向 landscape横向
*/
public void setDocumentSize(WordprocessingMLPackage wordPackage, ObjectFactory factory, String width, String height, STPageOrientation stValue) {
SectPr sectPr = getDocSectPr(wordPackage);
PgSz pgSz = sectPr.getPgSz();
if (pgSz == null) {
pgSz = factory.createSectPrPgSz();
sectPr.setPgSz(pgSz);
}
if (StringUtils.isNotBlank(width)) {
pgSz.setW(new BigInteger(width));
}
if (StringUtils.isNotBlank(height)) {
pgSz.setH(new BigInteger(height));
}
if (stValue != null) {
pgSz.setOrient(stValue);
}
}
Aggregations