public PropertyResolver getPropertyResolver() { if (propertyResolver==null) { try { propertyResolver = new PropertyResolver( (WordprocessingMLPackage)this.pack); } catch (Docx4JException e) { e.printStackTrace(); } } return propertyResolver; }
/** @since 2.7.2 */ @Override public OpcPackage clone() { OpcPackage result = null; // Zip it up ByteArrayOutputStream baos = new ByteArrayOutputStream(); SaveToZipFile saver = new SaveToZipFile(this); try { saver.save(baos); result = load(new ByteArrayInputStream(baos.toByteArray())); } catch (Docx4JException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; }
e.printStackTrace(); continue;
e.printStackTrace(); } catch (UnsupportedEncodingException e) {
public PropertyResolver getResolver() { if (myResolver == null) { try { myResolver = new PropertyResolver(myPackage); } catch (Docx4JException e) { e.printStackTrace(); } } return myResolver; }
public static WordprocessingMLPackage getDefaultTemplate(InputStream inputStream) { try { final WordprocessingMLPackage mlPackage = WordprocessingMLPackage.load(inputStream); return mlPackage; } catch (Docx4JException e) { e.printStackTrace(); } return null; }
@Override public Part getContainerPart() { try { return myDocx.getFootnotesPart(); } catch (Docx4JException e) { e.printStackTrace(); return myDocx.getDocxDocument(); } }
public void renderHtmlBlock(final HtmlBlockBase node, final DocxRendererContext docx, boolean suppress, boolean escape) { if (suppress) return; if (escape) { String normalizeEOL = node.getChars().normalizeEOL(); if (node instanceof HtmlBlock) { if (normalizeEOL.length() > 0 && normalizeEOL.charAt(normalizeEOL.length() - 1) == '\n') { // leave off the trailing EOL normalizeEOL = normalizeEOL.substring(0, normalizeEOL.length() - 1); } } // render as fenced code docx.renderFencedCodeLines(node.getContentLines()); //P p = docx.createP(); //docx.text(normalizeEOL); } else { try { docx.getDocxDocument().addAltChunk(AltChunkType.Html, node.getChars().toString().getBytes(Charset.forName("UTF-8"))); } catch (Docx4JException e) { e.printStackTrace(); } } }
/** * Render the tree of nodes to DocX. * * @param node the root node * @return the rendered HTML */ public String render(Node node) { WordprocessingMLPackage mlPackage = getDefaultTemplate(); render(node, mlPackage); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { mlPackage.save(outputStream, Docx4J.FLAG_SAVE_FLAT_XML); final String s = options.get(RENDER_BODY_ONLY) ? XmlFormatter.formatDocumentBody(outputStream.toString("UTF-8")) : XmlDocxSorter.sortDocumentParts(outputStream.toString("UTF-8")); return s; } catch (Docx4JException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
@Override public RelationshipsPart getRelationshipsPart() { try { return myDocx.getFootnotesPart().getRelationshipsPart(); } catch (Docx4JException e) { e.printStackTrace(); return myDocx.getDocxDocument().getRelationshipsPart(); } }
private void initializeStyleNames(WordprocessingMLPackage out) { final StyleDefinitionsPart styleDefinitionsPart = out.getMainDocumentPart().getStyleDefinitionsPart(); try { final Styles contents = styleDefinitionsPart.getContents(); final List<Style> styles = contents.getStyle(); for (Style style : styles) { final String styleId = style.getStyleId(); final String styleName = style.getName().getVal(); styleIdToStyleName.put(styleId, styleName); nameToStyleStyleId.put(styleName, styleId); } } catch (Docx4JException e) { e.printStackTrace(); } } }
public void renderInlineHtml(final HtmlInlineBase node, final DocxRendererContext docx, boolean suppress, boolean escape) { if (linebreakOnInlineHtmlBr && node.getChars().unescape().matches("<br\\s*/?>")) { // start a new hard-break docx.addLineBreak(); } else { if (suppress) return; if (escape) { // render as inline code docx.contextFramed(new Runnable() { @Override public void run() { docx.setRunFormatProvider(new SourceCodeRunFormatProvider<>(docx, options.noCharacterStyles, options.codeHighlightShading)); docx.text(node.getChars().normalizeEOL()); } }); } else { try { docx.getDocxDocument().addAltChunk(AltChunkType.Html, node.getChars().toString().getBytes()); } catch (Docx4JException e) { e.printStackTrace(); } } } }
private void render(Footnote node, final DocxRendererContext docx) { final FootnoteBlock footnoteBlock = node.getFootnoteBlock(); if (footnoteBlock == null) { //just text final org.docx4j.wml.Text text = docx.addWrappedText(); text.setValue("[^"); docx.renderChildren(node); final org.docx4j.wml.Text text1 = docx.addWrappedText(); text1.setValue("]"); } else { try { BigInteger footnoteId = footnoteIDs.containsKey(footnoteBlock) ? footnoteIDs.get(footnoteBlock) : BigInteger.ZERO; final CTFtnEdn ftnEdn = docx.addFootnote(footnoteId); final BigInteger ftnEdnId = ftnEdn.getId(); if (ftnEdnId.compareTo(footnoteId) != 0) { // Word does not like re-using footnotes, so we create a new one for every reference //footnoteIDs.put(footnoteBlock, ftnEdnId); docx.contextFramed(new FootnoteFrame(docx, ftnEdn, footnoteBlock)); } } catch (Docx4JException e) { e.printStackTrace(); } } }
public BigInteger getNumPrFor(BigInteger baseNumID, Color color) { RPr rPr = getResolver().getEffectiveRPr(myOptions.PREFORMATTED_TEXT_STYLE); if (rPr != null && rPr.getColor() != null) { if (keepDiff(rPr.getColor(), color) == null) { return baseNumID; } } String colorID = String.format("%s:%s", baseNumID.toString(), color.getVal()); final BigInteger numID = myNumPrColorMap.get(colorID); if (numID != null) { return numID; } // we create a copy of the baseNubPr and add the changed color property final NumberingDefinitionsPart ndp = myDocumentPart.getNumberingDefinitionsPart(); try { final Numbering numbering = ndp.getContents(); final List<Numbering.Num> num = numbering.getNum(); final List<Numbering.AbstractNum> abstractNumList = numbering.getAbstractNum(); for (Numbering.AbstractNum abstractNum : abstractNumList) { if (abstractNum.getAbstractNumId().compareTo(baseNumID) == 0) { // we have our list to copy // TODO: create a copy and set the color it the list's rpr. } } return null; } catch (Docx4JException e) { e.printStackTrace(); } return null; }
public PropertyResolver getPropertyResolver() { if (propertyResolver==null) { try { propertyResolver = new PropertyResolver( (WordprocessingMLPackage)this.pack); } catch (Docx4JException e) { e.printStackTrace(); } } return propertyResolver; }
private static WordprocessingMLPackage export(String xhtml) { WordprocessingMLPackage wordMLPackage = null; try { wordMLPackage = WordprocessingMLPackage.createPackage(); List<Object> content = XHTMLImporter.convert(xhtml, null, wordMLPackage); wordMLPackage.getMainDocumentPart().getContent().addAll(content); } catch (Docx4JException e) { // TODO Auto-generated catch block e.printStackTrace(); } return wordMLPackage; }
public class PlayDocx4J { public static void main(String[] args) { try { WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); wordMLPackage.getMainDocumentPart().addParagraphOfText("Hello Word!"); wordMLPackage.save(new java.io.File("c:/test/helloword.docx")); } catch (Docx4JException e) { System.err.println("ERROR " + e.getMessage()); e.printStackTrace(); } } }
/** @since 2.7.2 */ @Override public OpcPackage clone() { OpcPackage result = null; // Zip it up ByteArrayOutputStream baos = new ByteArrayOutputStream(); SaveToZipFile saver = new SaveToZipFile(this); try { saver.save(baos); result = load(new ByteArrayInputStream(baos.toByteArray())); } catch (Docx4JException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; }
e.printStackTrace(); continue;
} catch (Docx4JException e) { e.printStackTrace();