Examples of MainDocumentPart


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

  @Test
  public  void twoLists() throws Exception
   
    WordprocessingMLPackage wordMLPackage = createPkg();
   
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();

    mdp.getContent().add(createUnnumberedP());
   
    mdp.getContent().add(createNumberedP(1,0));
    mdp.getContent().add(createNumberedP(2,0));

    mdp.getContent().add(createUnnumberedP());
   
    //wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_simpleTest.docx"));
   
    ListsToContentControls.process(wordMLPackage);
   
    System.out.println(mdp.getXML());
   
 
View Full Code Here

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

  @Test
  public  void existingControl() throws Exception
   
    WordprocessingMLPackage wordMLPackage = createPkg();
   
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
   
    SdtBlock sdtBlock = new SdtBlock();
    SdtContentBlock sdtContentBlock = new SdtContentBlock();
   
    sdtBlock.setSdtContent(sdtContentBlock);
   
    mdp.getContent().add(sdtBlock);
   
    sdtBlock.getSdtContent().getContent().add(createUnnumberedP());
   
    sdtBlock.getSdtContent().getContent().add(createNumberedP(1,0));
    sdtBlock.getSdtContent().getContent().add(createNumberedP(1,0));

    sdtBlock.getSdtContent().getContent().add(createUnnumberedP());

    ListsToContentControls.process(wordMLPackage);
   
    System.out.println(mdp.getXML());
   
  }
View Full Code Here

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

  @Test
  public  void tableCell() throws Exception
   
    WordprocessingMLPackage wordMLPackage = createPkg();
   
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
   
    org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();

    Tbl tbl = wmlObjectFactory.createTbl();
    JAXBElement<org.docx4j.wml.Tbl> tblWrapped = wmlObjectFactory.createCTFtnEdnTbl(tbl);
        // Create object for tr
        Tr tr = wmlObjectFactory.createTr();
        tbl.getContent().add( tr);
            // Create object for tc (wrapped in JAXBElement)
            Tc tc = wmlObjectFactory.createTc();
            JAXBElement<org.docx4j.wml.Tc> tcWrapped = wmlObjectFactory.createTrTc(tc);
            tr.getContent().add( tcWrapped);    
   
    mdp.getContent().add(tbl);
   
    tc.getContent().add(createUnnumberedP());
   
    tc.getContent().add(createNumberedP(1,0));
    tc.getContent().add(createNumberedP(1,0));

    tc.getContent().add(createUnnumberedP());

    ListsToContentControls.process(wordMLPackage);
   
    System.out.println(mdp.getXML());
   
  }
View Full Code Here

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

  @Test
  public  void EndToEnd() throws Exception
   
    WordprocessingMLPackage wordMLPackage = createPkg();
   
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();

    mdp.getContent().add(createUnnumberedP());
   
    mdp.getContent().add(createNumberedP(1,0));
    mdp.getContent().add(createNumberedP(2,0));

    mdp.getContent().add(createUnnumberedP());
   
    //wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_simpleTest.docx"));
   
//    ListsToContentControls.process(wordMLPackage);
   
    System.out.println(mdp.getXML());
   
    toHTML( wordMLPackage);
   
 
View Full Code Here

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

        .getDocProperties();
    // TODO

    // Convert main document part

    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
    org.docx4j.wml.ObjectFactory factory = new org.docx4j.wml.ObjectFactory();

    Range r = doc.getRange();

    for (int x = 0; x < r.numSections(); x++) {
      Section s = r.getSection(x);

      // TODO - convert section

      for (int y = 0; y < s.numParagraphs(); y++) {
        Paragraph p = s.getParagraph(y);

        if (p.isInTable()) {
          Table t = s.getTable(p);
          int cl = numCol(t);

          log.info("Found " + t.numRows() + "x" + cl
              + " table - TODO - convert");

          handleTable(wordMLPackage, doc,t, stylesheet, documentPart, factory);

          // addTODO(factory, wmlP, "[TABLE " + + t.numRows() + "x" +
          // cl
          // + " - can't convert tables yet]");

          y += t.numParagraphs() - 1;
        }

        else {
          org.docx4j.wml.P paraToAdd = handleP(wordMLPackage, doc,
              p, stylesheet, documentPart, factory);

          documentPart.addObject(paraToAdd);
        }

      }
    }
View Full Code Here

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

  public static void main(String[] args) throws Exception {
 
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
        .load(new java.io.File(System.getProperty("user.dir") + "/CommentsDeleter.docx"));
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();

    org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document) documentPart
        .getJaxbElement();
    Body body = wmlDocumentEl.getBody();
 
    CommentFinder cf = new CommentFinder();
      new TraversalUtil(body, cf);
View Full Code Here

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

  public static void main(String[] args) throws Exception {

    String inputfilepath = System.getProperty("user.dir") + "/checkbox.docx";
       
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));   
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
       
    ClassFinder finder = new ClassFinder(FldChar.class); // <----- change this to suit
    new TraversalUtil(documentPart.getContent(), finder);
   
    System.out.println("got " + finder.results.size()  );
   
    for (Object o : finder.results) {
           
View Full Code Here

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

       
    // Create a package
    WordprocessingMLPackage wmlPack = new WordprocessingMLPackage();

    // Create main document part
    MainDocumentPart wordDocumentPart = new MainDocumentPart();   
   
    // Create main document part content
    org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory();
    org.docx4j.wml.Body  body = factory.createBody();   
    org.docx4j.wml.Document wmlDocumentEl = factory.createDocument();
   
    wmlDocumentEl.setBody(body);
   
    // Create a basic sectPr using our Page model
    PageDimensions page = new PageDimensions();
    page.setPgSize(sz, landscape);
   
    SectPr sectPr = factory.createSectPr();
    body.setSectPr(sectPr);
    sectPr.setPgSzpage.getPgSz() );
    sectPr.setPgMar( page.getPgMar() );
       
    // Put the content in the part
    wordDocumentPart.setJaxbElement(wmlDocumentEl);
           
    // Add the main document part to the package relationships
    // (creating it if necessary)
    wmlPack.addTargetPart(wordDocumentPart);
       
    // Create a styles part
    Part stylesPart = new org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart();
    try {
      ((org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart) stylesPart)
          .unmarshalDefaultStyles();
     
      // Add the styles part to the main document part relationships
      // (creating it if necessary)
      wordDocumentPart.addTargetPart(stylesPart); // NB - add it to main doc part, not package!     
     
    } catch (Exception e) {
      // TODO: handle exception
      //e.printStackTrace(); 
      log.error(e.getMessage(), e);
View Full Code Here

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

       
    if (ADD_TO_HEADER) {
      HeaderPart hp = wordMLPackage.getDocumentModel().getSections().get(0).getHeaderFooterPolicy().getDefaultHeader();
      hp.addAltChunk(AltChunkType.WordprocessingML, new FileInputStream(chunkPath) );
    } else {
      MainDocumentPart main = wordMLPackage.getMainDocumentPart();
      main.addAltChunk(AltChunkType.WordprocessingML, new FileInputStream(chunkPath) );
    }
   
    if (save) {   
      SaveToZipFile saver = new SaveToZipFile(wordMLPackage);
      saver.save(outputfilepath);
View Full Code Here

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

   
       
    boolean save = true;

    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
   
    // Example 1: add text in Title style
    mdp.addStyledParagraphOfText("Title", "Example 1");

    // Example 2: add normal paragraph (no explicit style)
    mdp.addParagraphOfText("Example 2");
   
    // Example 3a: bold text
    // To get bold text, you must set the run's rPr@w:b,
      // so you can't use the addParagraphOfText convenience method
   
    org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory();
    org.docx4j.wml.P  p = factory.createP();

    org.docx4j.wml.Text  t = factory.createText();
    t.setValue("Example 3a (bold)");

    org.docx4j.wml.R  run = factory.createR();
    run.getContent().add(t);   
   
    p.getContent().add(run);
   
   
    org.docx4j.wml.RPr rpr = factory.createRPr();   
    org.docx4j.wml.BooleanDefaultTrue b = new org.docx4j.wml.BooleanDefaultTrue();
      b.setVal(true);     
      rpr.setB(b);
     
    run.setRPr(rpr);
   
    // Optionally, set pPr/rPr@w:b   
      org.docx4j.wml.PPr ppr = factory.createPPr();     
      p.setPPr( ppr );
      org.docx4j.wml.ParaRPr paraRpr = factory.createParaRPr();
      ppr.setRPr(paraRpr);     
      rpr.setB(b);
     
      mdp.getJaxbElement().getBody().getContent().add(p);
      // or just:
      // mdp.getContent().add(p);
      // but:
      // mdp.addObject(p);
      // is a better alternative if you are using a new style, since it
      // will ensure that the style is activated 

    // Example 3b: bold text
      // Well, actually you can use addParagraphOfText:
    P p3b = mdp.addParagraphOfText("Example 3b (bold)");
    R r3b = (R)p3b.getContent().get(0);
      // .. now set rPr (I'll just reuse the above object)
    r3b.setRPr(rpr);

     
      // Example 4: Here is an easier way:
      String str = "<w:p xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" ><w:r><w:rPr><w:b /></w:rPr><w:t>Example 4</w:t></w:r></w:p>";
     
      mdp.addObject(
            org.docx4j.XmlUtils.unmarshalString(str) );

     
      // Example 5: Let's add a table
      int writableWidthTwips = wordMLPackage.getDocumentModel().getSections().get(0).getPageDimensions().getWritableWidthTwips();
      int cols = 3;
      int cellWidthTwips = new Double(
                    Math.floor( (writableWidthTwips/cols ))
                      ).intValue();
     
      Tbl tbl = TblFactory.createTable(3, 3, cellWidthTwips);
      mdp.addObject(tbl);
     
   
       // Pretty print the main document part
    System.out.println(
        XmlUtils.marshaltoString(mdp.getJaxbElement(), true, true) );
   
    // Optionally save it
    if (save) {
      String filename = System.getProperty("user.dir") + "/OUT_CreateWordprocessingMLDocument.docx";
      wordMLPackage.save(new java.io.File(filename) );
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.