Package org.docx4j.wml

Examples of org.docx4j.wml.Body


   
    // 1. Load the Packages
    WordprocessingMLPackage newerPackage = WordprocessingMLPackage.load(new java.io.File(newerfilepath));
    WordprocessingMLPackage olderPackage = WordprocessingMLPackage.load(new java.io.File(olderfilepath));
   
    Body newerBody = ((Document)newerPackage.getMainDocumentPart().getJaxbElement()).getBody();
    Body olderBody = ((Document)olderPackage.getMainDocumentPart().getJaxbElement()).getBody();
   
    System.out.println("Differencing..");
   
    // 2. Do the differencing
    java.io.StringWriter sw = new java.io.StringWriter();
    javax.xml.transform.stream.StreamResult result = new javax.xml.transform.stream.StreamResult(
        sw);
    Calendar changeDate = null;
   
    Differencer pd = null;
    if (DIVIDE_AND_CONQUER) {

      Docx4jDriver.diff( XmlUtils.marshaltoW3CDomDocument(newerBody).getDocumentElement(),
          XmlUtils.marshaltoW3CDomDocument(olderBody).getDocumentElement(),
             sw);
        // The signature which takes Reader objects appears to be broken
     
    } else {

      pd = new Differencer();
      pd.setRelsDiffIdentifier("blagh"); // not necessary in this case
      pd.diff(newerBody, olderBody, result, "someone", changeDate,
          newerPackage.getMainDocumentPart().getRelationshipsPart(),
          olderPackage.getMainDocumentPart().getRelationshipsPart()
          );
    }
   
    // 3. Get the result
    String contentStr = sw.toString();
    System.out.println("Result: \n\n " + contentStr);
    Body newBody = (Body) XmlUtils.unwrap(
        XmlUtils.unmarshalString(contentStr));
   
    // 4. Display the result as a PDF
    // To do this, we'll replace the body in the newer document
    ((Document)newerPackage.getMainDocumentPart().getJaxbElement()).setBody(newBody);
View Full Code Here


    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
   
    org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document)documentPart.getJaxbElement();
    Body body =  wmlDocumentEl.getBody();
   
        ObjectFactory factory = Context.getWmlObjectFactory();
       
        /* Create the following:
         *
        <w:p>
          <w:r>
            <w:fldChar w:dirty="true" w:fldCharType="begin"/>
            <w:instrText xml:space="preserve">TOC \o &quot;1-3&quot; \h \z \ u \h</w:instrText>
          </w:r>
          <w:r/>
          <w:r>
            <w:fldChar w:fldCharType="end"/>
          </w:r>
        </w:p>         */       
        P paragraphForTOC = factory.createP();          
        R r = factory.createR();

        FldChar fldchar = factory.createFldChar();
        fldchar.setFldCharType(STFldCharType.BEGIN);
        fldchar.setDirty(true);
        r.getContent().add(getWrappedFldChar(fldchar));
        paragraphForTOC.getContent().add(r);

        R r1 = factory.createR();
        Text txt = new Text();
        txt.setSpace("preserve");
        txt.setValue("TOC \\o \"1-3\" \\h \\z \\u \\h");
        r.getContent().add(factory.createRInstrText(txt) );
        paragraphForTOC.getContent().add(r1);

        FldChar fldcharend = factory.createFldChar();
        fldcharend.setFldCharType(STFldCharType.END);
        R r2 = factory.createR();
        r2.getContent().add(getWrappedFldChar(fldcharend));
        paragraphForTOC.getContent().add(r2);
           
    body.getContent().add(paragraphForTOC);
   
    documentPart.addStyledParagraphOfText("Heading1", "Hello 1");
    documentPart.addStyledParagraphOfText("Heading2", "Hello 2");
    documentPart.addStyledParagraphOfText("Heading3", "Hello 3");
    documentPart.addStyledParagraphOfText("Heading1", "Hello 1");
View Full Code Here

        .load(new java.io.File(inputfilepath));
    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

    // 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();
   
    BookmarksReplaceWithText bti = new BookmarksReplaceWithText();

    bti.replaceBookmarkContents(body.getContent(), map);
   
    // After
    // System.out.println(XmlUtils.marshaltoString(documentPart.getJaxbElement(), true, true));
   
    // save the docx...
View Full Code Here

        }
       
       
        org.docx4j.wml.Document wmlDocumentEl
          = wordMLPackage.getMainDocumentPart().getJaxbElement();
        Body body =  wmlDocumentEl.getBody();
        List <Object> bodyChildren = body.getEGBlockLevelElts();
       
        traverseBlockLevelContent( bodyChildren, pdfDoc );       
           
      } catch (Exception e) {
        throw new Docx4JException("iTextissues", e);
View Full Code Here

    // 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));
   
    // or save the docx...
View Full Code Here

      }     
    }
     
    // Change r:embed to r:link
    org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document)documentPart.getJaxbElement();
    Body body =  wmlDocumentEl.getBody();
           
    SingleTraversalUtilVisitorCallback imageVisitor
      = new SingleTraversalUtilVisitorCallback(
          new TraversalUtilBlipVisitor());
    imageVisitor.walkJAXBElements(body);
View Full Code Here

       
        File tempTargetFile = createTempFile();
        FileInputStream tempTargetFis = null;
        try {
            Element bodyEl = Jdom2.htmlBodyFor(htmlDoc);
            Body docXBody = Docx.docxBodyFor(docxTemplate);

            merge(bodyEl, docXBody, matchingPolicy);

            docxTemplate.save(tempTargetFile);
            tempTargetFis = new FileInputStream(tempTargetFile);
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

       
        File tempTargetFile = createTempFile();
        FileInputStream tempTargetFis = null;
        try {
            Element bodyEl = Jdom2.htmlBodyFor(htmlDoc);
            Body docXBody = Docx.docxBodyFor(docxTemplate);

            merge(bodyEl, docXBody, matchingPolicy);

            docxTemplate.save(tempTargetFile);
            tempTargetFis = new FileInputStream(tempTargetFile);
View Full Code Here

TOP

Related Classes of org.docx4j.wml.Body

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.