Search in sources :

Example 1 with ObjectFactory

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;
}
Also used : P(org.docx4j.wml.P) Drawing(org.docx4j.wml.Drawing) R(org.docx4j.wml.R) ObjectFactory(org.docx4j.wml.ObjectFactory) Inline(org.docx4j.dml.wordprocessingDrawing.Inline) BinaryPartAbstractImage(org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)

Example 2 with ObjectFactory

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"));
}
Also used : ObjectFactory(org.docx4j.wml.ObjectFactory) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) Relationship(org.docx4j.relationships.Relationship) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File)

Example 3 with ObjectFactory

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"));
}
Also used : ObjectFactory(org.docx4j.wml.ObjectFactory) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) Relationship(org.docx4j.relationships.Relationship) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File)

Example 4 with ObjectFactory

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"));
}
Also used : ObjectFactory(org.docx4j.wml.ObjectFactory) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File)

Example 5 with ObjectFactory

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"));
}
Also used : ObjectFactory(org.docx4j.wml.ObjectFactory) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File) Tbl(org.docx4j.wml.Tbl)

Aggregations

ObjectFactory (org.docx4j.wml.ObjectFactory)26 P (org.docx4j.wml.P)18 R (org.docx4j.wml.R)17 File (java.io.File)8 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)8 Drawing (org.docx4j.wml.Drawing)8 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)7 Text (org.docx4j.wml.Text)6 BooleanDefaultTrue (org.docx4j.wml.BooleanDefaultTrue)5 RPr (org.docx4j.wml.RPr)5 Relationship (org.docx4j.relationships.Relationship)4 PPr (org.docx4j.wml.PPr)4 Tbl (org.docx4j.wml.Tbl)4 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)3 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)3 Tc (org.docx4j.wml.Tc)3 Tr (org.docx4j.wml.Tr)3 Color (org.docx4j.wml.Color)2 Hyperlink (org.docx4j.wml.P.Hyperlink)2 NumPr (org.docx4j.wml.PPrBase.NumPr)2