use of org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart in project Java-Tutorial by gpcodervn.
the class Write_Image method main.
public static void main(String[] args) throws Exception {
WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart mainDocumentPart = wordPackage.getMainDocumentPart();
mainDocumentPart.addStyledParagraphOfText("Title", "Hello World!");
mainDocumentPart.addParagraphOfText("Welcome To Baeldung");
File image = new File("resources/image.png");
byte[] fileContent = Files.readAllBytes(image.toPath());
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordPackage, fileContent);
Inline inline = imagePart.createImageInline("Baeldung Image (filename hint)", "Alt Text", 1, 2, false);
P Imageparagraph = addImageToParagraph(inline);
mainDocumentPart.getContent().add(Imageparagraph);
File exportFile = new File("output/welcome3.docx");
wordPackage.save(exportFile);
System.out.println("Done!");
}
use of org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart in project docx4j-template by vindell.
the class Docx4J_例子2 method addPageBreak.
// 分页
public void addPageBreak(WordprocessingMLPackage wordMLPackage, ObjectFactory factory, STBrType sTBrType) {
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
Br breakObj = new Br();
breakObj.setType(sTBrType);
P paragraph = factory.createP();
paragraph.getContent().add(breakObj);
documentPart.addObject(paragraph);
}
use of org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart 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.openpackaging.parts.WordprocessingML.MainDocumentPart in project docx4j-template by vindell.
the class Docx4J_简单例子2 method addPageBreak.
// 分页
public void addPageBreak(WordprocessingMLPackage wordMLPackage, ObjectFactory factory) {
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
Br breakObj = new Br();
breakObj.setType(STBrType.PAGE);
P paragraph = factory.createP();
paragraph.getContent().add(breakObj);
documentPart.addObject(paragraph);
}
use of org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart 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"));
}
Aggregations