use of org.docx4j.wml.ObjectFactory in project Java-Tutorial by gpcodervn.
the class Docx4jUtils method newImage.
public P newImage(WordprocessingMLPackage wordMLPackage, byte[] bytes, String filenameHint, String altText, int id1, int id2, long cx) throws Exception {
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
Inline inline = imagePart.createImageInline(filenameHint, altText, id1, id2, cx, false);
// Now add the inline in w:p/w:r/w:drawing
ObjectFactory factory = Context.getWmlObjectFactory();
P p = factory.createP();
R run = factory.createR();
p.getContent().add(run);
Drawing drawing = factory.createDrawing();
run.getContent().add(drawing);
drawing.getAnchorOrInline().add(inline);
return p;
}
use of org.docx4j.wml.ObjectFactory in project docx4j-template by vindell.
the class Docx4J_简单例子 method main.
public static void main(String[] args) throws Exception {
Docx4J_简单例子 t = new Docx4J_简单例子();
WordprocessingMLPackage wordMLPackage = t.createWordprocessingMLPackage();
MainDocumentPart mp = wordMLPackage.getMainDocumentPart();
ObjectFactory factory = Context.getWmlObjectFactory();
// 页眉
Relationship relationship = t.createHeaderPart(wordMLPackage, mp, factory);
t.createHeaderReference(wordMLPackage, mp, factory, relationship);
t.addParagraphTest(wordMLPackage, mp, factory);
t.addPageBreak(wordMLPackage, factory);
// 页脚
t.createNormalTableTest(wordMLPackage, mp, factory);
relationship = t.createFooterPageNumPart(wordMLPackage, mp, factory);
t.createFooterReference(wordMLPackage, mp, factory, relationship);
t.saveWordPackage(wordMLPackage, new File("f:/saveFile/temp/s_simple.docx"));
}
use of org.docx4j.wml.ObjectFactory in project docx4j-template by vindell.
the class Docx4J_简单例子2 method main.
public static void main(String[] args) throws Exception {
Docx4J_简单例子 t = new Docx4J_简单例子();
WordprocessingMLPackage wordMLPackage = t.createWordprocessingMLPackage();
MainDocumentPart mp = wordMLPackage.getMainDocumentPart();
ObjectFactory factory = Context.getWmlObjectFactory();
// 图片页眉
// Relationship relationship =t.createHeaderPart(wordMLPackage, mp, factory);
// 文字页眉
Relationship relationship = t.createTextHeaderPart(wordMLPackage, mp, factory, "我是页眉,多创造,少抄袭", JcEnumeration.CENTER);
t.createHeaderReference(wordMLPackage, mp, factory, relationship);
t.addParagraphTest(wordMLPackage, mp, factory);
t.addPageBreak(wordMLPackage, factory);
t.createNormalTableTest(wordMLPackage, mp, factory);
// 页脚
relationship = t.createFooterPageNumPart(wordMLPackage, mp, factory);
t.createFooterReference(wordMLPackage, mp, factory, relationship);
t.saveWordPackage(wordMLPackage, new File("f:/saveFile/temp/s5_simple.docx"));
}
use of org.docx4j.wml.ObjectFactory in project docx4j-template by vindell.
the class Docx4j_创建批注_S3_Test method main.
public static void main(String[] args) throws Exception {
Docx4j_创建批注_S3_Test t = new Docx4j_创建批注_S3_Test();
WordprocessingMLPackage wordMLPackage = t.createWordprocessingMLPackage();
MainDocumentPart mp = wordMLPackage.getMainDocumentPart();
ObjectFactory factory = Context.getWmlObjectFactory();
t.testCreateComment(wordMLPackage, mp, factory);
t.saveWordPackage(wordMLPackage, new File("f:/saveFile/temp/sys_" + System.currentTimeMillis() + ".docx"));
}
use of org.docx4j.wml.ObjectFactory in project docx4j-template by vindell.
the class Docx4jStyle_S3 method testDocx4jCreateTable.
public void testDocx4jCreateTable() throws Exception {
boolean landscape = false;
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(PageSizePaper.A4, landscape);
ObjectFactory factory = Context.getWmlObjectFactory();
setPageMargins(wordMLPackage, factory);
String imgFilePath = "f:/saveFile/tmp/2sql日志.jpg";
Tbl table = createTableWithContent(wordMLPackage, factory, imgFilePath);
wordMLPackage.getMainDocumentPart().addObject(table);
wordMLPackage.save(new File("f:/saveFile/temp/sys_" + System.currentTimeMillis() + ".docx"));
}
Aggregations