/** * Create a linked image part, and attach it as a rel of the docx main document part * @param wordMLPackage * @param fileurl * @return * @throws Exception */ public static BinaryPartAbstractImage createLinkedImagePart(WordprocessingMLPackage wordMLPackage, URL fileurl) throws Exception { return createLinkedImagePart(wordMLPackage, wordMLPackage.getMainDocumentPart(), fileurl); }
/** * Possibility to put directly an image filePath instead of giving an image byte array * @param wordMLPackage * @param imageFile * */ public static BinaryPartAbstractImage createImagePart(WordprocessingMLPackage wordMLPackage, File imageFile) throws Exception { return createImagePart(wordMLPackage, wordMLPackage.getMainDocumentPart(), imageFile); }
public ListsToContentControls(WordprocessingMLPackage wmlPackage) { this.wmlPackage = wmlPackage; mainDocument = wmlPackage.getMainDocumentPart(); this.ndp=mainDocument.getNumberingDefinitionsPart(); stylesPart = wmlPackage.getMainDocumentPart().getStyleDefinitionsPart(); propertyResolver = wmlPackage.getMainDocumentPart().getPropertyResolver(); }
protected void resolveLinkedAbstractNum(WordprocessingMLPackage wmlPkg) { if (wmlPkg.getMainDocumentPart().getStyleDefinitionsPart(false)!=null && wmlPkg.getMainDocumentPart().getNumberingDefinitionsPart()!=null) { wmlPkg.getMainDocumentPart().getNumberingDefinitionsPart().resolveLinkedAbstractNum( wmlPkg.getMainDocumentPart().getStyleDefinitionsPart(false)); } }
private Style getDefaultPStyle() { if (defaultParagraphStyle==null) { defaultParagraphStyle = (wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart(false) != null ? wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart(false).getDefaultParagraphStyle() : null); } return defaultParagraphStyle; }
public static void main(String[] args) throws Exception { String inputfilepath = System.getProperty("user.dir") + "/sample-docs/Table.docx"; //String inputfilepath = System.getProperty("user.dir") + "/sample-docs/Word2007-fonts.docx"; WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath)); MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart(); org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document)documentPart.getJaxbElement(); Writer out = new OutputStreamWriter(System.out); extractText(wmlDocumentEl, out); //out.flush(); out.close(); }
/** Combine complex fields to w:fldSimple * */ public static void process(WordprocessingMLPackage wmlPackage) { log.info("starting"); TraversalUtil.visit(wmlPackage, false, COMBINE_VISITOR); if (log.isDebugEnabled()) { log.debug(XmlUtils.marshaltoString(wmlPackage.getMainDocumentPart().getJaxbElement(), true, true)); } }
protected StyleTree initializeStyleTree() { //catching and swallowing an exception here isn't good, //that would cause later on a NPE return getWmlPackage().getMainDocumentPart().getStyleTree(); }
public String getCss() { WordprocessingMLPackage wmlPackage = (WordprocessingMLPackage)htmlSettings.getWmlPackage(); StringBuilder buffer = new StringBuilder(); HtmlCssHelper.createCssForStyles(wmlPackage, wmlPackage.getMainDocumentPart().getStyleTree(), buffer); return buffer.toString(); }
private void process() { propertyResolver = wmlPackage.getMainDocumentPart().getPropertyResolver(); List<Object> newContent = process(wmlPackage.getMainDocumentPart().getContent()); wmlPackage.getMainDocumentPart().getJaxbElement().getBody().getContent().clear(); wmlPackage.getMainDocumentPart().getJaxbElement().getBody().getContent().addAll(newContent); }
@Deprecated // see instead org.docx4j.convert.out.Converter public static Node getFootnote(WordprocessingMLPackage wmlPackage, String id) { CTFootnotes footnotes = wmlPackage.getMainDocumentPart().getFootnotesPart().getJaxbElement(); int pos = Integer.parseInt(id); // No @XmlRootElement on CTFtnEdn, so .. CTFtnEdn ftn = (CTFtnEdn)footnotes.getFootnote().get(pos); Document d = XmlUtils.marshaltoW3CDomDocument( ftn, Context.jc, Namespaces.NS_WORD12, "footnote", CTFtnEdn.class ); log.debug("Footnote " + id + ": " + XmlUtils.w3CDomNodeToString(d)); return d; }
public PropertyResolver(WordprocessingMLPackage wordMLPackage) throws Docx4JException { this.wordMLPackage = wordMLPackage; MainDocumentPart mdp = wordMLPackage.getMainDocumentPart(); styleDefinitionsPart = mdp.getStyleDefinitionsPart(true); themePart = mdp.getThemePart(); numberingDefinitionsPart = mdp.getNumberingDefinitionsPart(); if (wordMLPackage.getMainDocumentPart().getDocumentSettingsPart()!=null && wordMLPackage.getMainDocumentPart().getDocumentSettingsPart().getContents()!=null) { themeFontLang = wordMLPackage.getMainDocumentPart().getDocumentSettingsPart().getContents().getThemeFontLang(); } init(); }
/** * @param args * @throws Docx4JException */ public static void main(String[] args) throws Docx4JException { WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load( new java.io.File( System.getProperty("user.dir") + "/aq1.docx")); FieldUpdater fu = new FieldUpdater(wordMLPackage); fu.update(true); System.out.println(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true)); }
/** * If a page-break w:br w:type="page" is found within a run with some formatting applied to it * then it will be generated into an fo:inline tag. This page break will be ignored by fop. This class * moves the page-breaks to the enclosing block. */ public static void process(WordprocessingMLPackage wmlPackage) { Body body = wmlPackage.getMainDocumentPart().getJaxbElement().getBody(); //TODO: Convert to visitor movePageBreaks(body); }
/** * Enable the hyperlinkStyle in the docx. * * @param wordMLPackage * @param hyperlinkStyleId */ public void activateHyperlinkStyle(WordprocessingMLPackage wordMLPackage) { if (hyperlinkStyleId !=null) { wordMLPackage.getMainDocumentPart().getPropertyResolver().activateStyle(getHyperlinkStyleId()); } }
/** * If the first w:p starts with a w:sectPr, this is moved into a * new following w:p. This prevents the creation of an empty fo:flow, * which causes a validation exception in FOP. */ public static void process(WordprocessingMLPackage wmlPackage) { Body body = wmlPackage.getMainDocumentPart().getJaxbElement().getBody(); moveSectPr(body); }
private int initBookmarkIdStart() { int highestId = 0; RangeFinder rt = new RangeFinder("CTBookmark", "CTMarkupRange"); new TraversalUtil(wordMLPackage.getMainDocumentPart().getContent(), rt); for (CTBookmark bm : rt.getStarts()) { BigInteger id = bm.getId(); if (id!=null && id.intValue()>highestId) { highestId = id.intValue(); } } return highestId +1; }
@Override protected Document getSourceDocument(HTMLSettings conversionSettings, HTMLConversionContext conversionContext) throws Docx4JException { WordprocessingMLPackage wmlPackage = conversionContext.getWmlPackage(); //TODO: the docx2xhtml-core.xslt only knows about the MainDocumentPart, therefore it's //unable to process any sections.... return XmlUtils.marshaltoW3CDomDocument(wmlPackage.getMainDocumentPart().getJaxbElement()); }
protected XPathsPart createXPathsPart(WordprocessingMLPackage pkgOut, Xpaths xpaths) throws InvalidFormatException { xPathsPart = new XPathsPart(new PartName("/customXml/item1.xml")); pkgOut.getMainDocumentPart().addTargetPart(xPathsPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS); addPropertiesPart(pkgOut, xPathsPart, "http://opendope.org/xpaths"); xPathsPart.setJaxbElement(xpaths); return xPathsPart; }
protected ConditionsPart createConditionsPart(WordprocessingMLPackage pkgOut, Conditions conditions) throws InvalidFormatException { conditionsPart = new ConditionsPart(new PartName("/customXml/item1.xml")); // name doesn't matter pkgOut.getMainDocumentPart().addTargetPart(conditionsPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS); // Word will silently drop the CXPs if they aren't added to the MDP! addPropertiesPart(pkgOut, conditionsPart, "http://opendope.org/conditions"); conditionsPart.setJaxbElement(conditions); return conditionsPart; }