Package org.docx4j.openpackaging.parts.WordprocessingML

Examples of org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart


   
    WordprocessingMLPackage wordMLPackage=null;
    try {
      wordMLPackage = WordprocessingMLPackage.createPackage();
    } catch (InvalidFormatException e) {}
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
   
    // Main Document Part
    mdp.getJaxbElement().setBody(transitionContainer.getBody());
   
    // DEBUGGING: if Word can't open the resulting docx,
    // a process for working out why is to
    // make sure it works with just the main document part,
    // then each of the following 3 parts, one by one.
    // What you need to do is to compare the XSLT output for the part
    // (XmlUtils.marshaltoString for the relevant part is usually
    //  enough) to what ECMA 376 requires.
    if (!mainDocOnly) {
   
      // Styles
      mdp.getStyleDefinitionsPart(true).setJaxbElement(transitionContainer.getStyles());
     
      // Numbering
      try {
        NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
        ndp.setJaxbElement(transitionContainer.getNumbering());
        mdp.addTargetPart(ndp);
       
        // fix attributes
        // <w:multiLevelType w:val="Multilevel"/> should start with lower case
        for (AbstractNum anum : ndp.getJaxbElement().getAbstractNum()) {
          if (anum.getMultiLevelType()==null) continue;
          String multiLevelType = anum.getMultiLevelType().getVal();
          multiLevelType = multiLevelType.substring(0, 1).toLowerCase() + multiLevelType.substring(1);
          anum.getMultiLevelType().setVal(multiLevelType);
        }
       
      } catch (InvalidFormatException e) {}
     
      // Fonts
      try {
        FontTablePart fontsPart = new FontTablePart();
        fontsPart.setJaxbElement(transitionContainer.getFonts());
               
        mdp.addTargetPart(fontsPart);
      } catch (InvalidFormatException e) {}
    }
   
    return wordMLPackage;
   
View Full Code Here


   */

  public static void main(String[] args) throws Exception {
   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
   
    // Create hyperlink
    Hyperlink link = createHyperlink(mdp, "http://slashdot.org");
   
    // Add it to a paragraph
    org.docx4j.wml.P paragraph = Context.getWmlObjectFactory().createP();
    paragraph.getContent().add( link );
    mdp.addObject(paragraph);
   
    // Now save it
    wordMLPackage.save(new java.io.File(System.getProperty("user.dir") + "/OUT_HyperlinkTest.docx") );
   
    // Uncomment to display the result as Flat OPC XML
View Full Code Here

        }
    }

    public void documentTraverse(PrintStream out) throws Docx4JException {
        WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(file);
        MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();

        org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document) documentPart.getJaxbElement();
        Body body = wmlDocumentEl.getBody();

        new TraversalUtil(body,

            new Callback() {
View Full Code Here

        text.setValue(value);
        return true;
    }

    public static Body docxBodyFor(WordprocessingMLPackage docxPkg) {
        MainDocumentPart docxMdp = docxPkg.getMainDocumentPart();
       
        org.docx4j.wml.Document docxDoc = (org.docx4j.wml.Document) docxMdp.getJaxbElement();
        return docxDoc.getBody();
    }
View Full Code Here

        }
    }

    public void documentTraverse(PrintStream out) throws Docx4JException {
        WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(file);
        MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();

        org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document) documentPart.getJaxbElement();
        Body body = wmlDocumentEl.getBody();

        new TraversalUtil(body,

            new Callback() {
View Full Code Here

        text.setValue(value);
        return true;
    }

    public static Body docxBodyFor(WordprocessingMLPackage docxPkg) {
        MainDocumentPart docxMdp = docxPkg.getMainDocumentPart();
       
        org.docx4j.wml.Document docxDoc = (org.docx4j.wml.Document) docxMdp.getJaxbElement();
        return docxDoc.getBody();
    }
View Full Code Here

  public static void main(String[] args) throws Exception
  {
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
        .load(new java.io.File("data/docx4j/Docx4j_BookmarkAdd.docx"));
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
   
    // Before..
    // System.out.println(XmlUtils.marshaltoString(documentPart.getJaxbElement(), true, true));
   
    org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document) documentPart
        .getJaxbElement();
    Body body = wmlDocumentEl.getBody();
   
    fixRange(body.getContent(), "CTBookmark", "CTMarkupRange");
   
    // After
    System.out.println(XmlUtils.marshaltoString(documentPart.getJaxbElement(), true, true));
   
    wordMLPackage.save(new java.io.File("data/docx4j/Docx4jBookmarkDeleted.docx"));
    System.out.println("Done.");
  }
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.