use of org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart in project docx4j-template by vindell.
the class AddingAPageBreak method addPageBreak.
/**
* 向文档添加一个换行符
*/
private static void addPageBreak() {
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
Br breakObj = new Br();
breakObj.setType(STBrType.PAGE);
P paragraph = factory.createP();
paragraph.getContent().add(breakObj);
documentPart.getJaxbElement().getBody().getContent().add(paragraph);
}
use of org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart in project docx4j-template by vindell.
the class WordprocessingMLTemplateWriter method writeToStream.
public static void writeToStream(WordprocessingMLPackage wmlPackage, OutputStream output) throws IOException, Docx4JException {
Assert.notNull(wmlPackage, " wmlPackage is not specified!");
Assert.notNull(output, " output is not specified!");
InputStream input = null;
try {
// Document对象
MainDocumentPart document = wmlPackage.getMainDocumentPart();
// Document XML
String documentXML = XmlUtils.marshaltoString(wmlPackage);
// 转成字节输入流
input = IOUtils.toBufferedInputStream(new ByteArrayInputStream(documentXML.getBytes()));
// 输出模板
IOUtils.copy(input, output);
} finally {
IOUtils.closeQuietly(input);
}
}
use of org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart in project docx4j-template by vindell.
the class SdtFinder_2 method printSdtContent.
public void printSdtContent(String filePath) throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File(filePath));
MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
Document wmlDocumentEl = (Document) mdp.getContents();
Body body = wmlDocumentEl.getBody();
SdtFinder_2 sdtFinder = new SdtFinder_2();
new TraversalUtil(body, sdtFinder);
for (Child sdtChild : sdtFinder.sdtList) {
if (sdtChild instanceof SdtRun) {
SdtRun sdtRun = (SdtRun) sdtChild;
SdtPr sdtPr = sdtRun.getSdtPr();
printSdtPrContent(sdtPr);
SdtContent sdtContent = sdtRun.getSdtContent();
System.out.println("-----------p content=" + getSdtContentContent(sdtContent));
} else if (sdtChild instanceof CTSdtCell) {
CTSdtCell sdtCell = (CTSdtCell) sdtChild;
SdtPr sdtPr = sdtCell.getSdtPr();
printSdtPrContent(sdtPr);
SdtContent sdtContent = sdtCell.getSdtContent();
System.out.println("-----------table content=" + getSdtContentContent(sdtContent));
} else if (sdtChild instanceof SdtBlock) {
SdtBlock sdtBlock = (SdtBlock) sdtChild;
SdtPr sdtPr = sdtBlock.getSdtPr();
printSdtPrContent(sdtPr);
SdtContent sdtContent = sdtBlock.getSdtContent();
System.out.println("-----------sdtblock content=" + getSdtContentContent(sdtContent));
}
}
}
use of org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart in project docx4j-template by vindell.
the class HtmlToDOCDemo method replaceRichText.
public static void replaceRichText(WordprocessingMLPackage wordMLPackage, Map<String, String> richTextMap) throws Docx4JException, JAXBException {
MainDocumentPart document = wordMLPackage.getMainDocumentPart();
Map<String, List<Object>> textNodeMap = new HashMap<String, List<Object>>();
findRichTextNode(textNodeMap, document.getContents().getBody(), null);
Iterator<String> iterator = richTextMap.keySet().iterator();
while (iterator.hasNext()) {
String textTag = iterator.next();
List<Object> textNodeList = textNodeMap.get(textTag);
if (textNodeList != null && richTextMap.containsKey(textTag)) {
List<Object> textObjList = convertToWmlObject(wordMLPackage, richTextMap.get(textTag));
for (int i = 0, iSize = textNodeList.size(); i < iSize; i++) {
Object nodeObject = textNodeList.get(i);
if (nodeObject != null) {
// setWmlPprSetting(textNodeList.get(i), textObjList);
TraversalUtil.replaceChildren(nodeObject, textObjList);
}
}
}
}
}
use of org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart in project flexmark-java by vsch.
the class CoreNodeDocxRenderer method render.
private void render(final Node node, final DocxRendererContext docx) {
BasedSequence chars = node.getChars();
MainDocumentPart mdp = docx.getDocxDocument();
if (node instanceof Block) {
docx.setBlockFormatProvider(new BlockFormatProviderBase<Node>(docx, docx.getDocxRendererOptions().LOOSE_PARAGRAPH_STYLE));
docx.createP();
docx.renderChildren(node);
} else {
docx.text(chars.unescape());
}
}
Aggregations