Examples of WordprocessingMLPackage


Examples of org.docx4j.openpackaging.packages.WordprocessingMLPackage

    return p;
   
 
  protected WordprocessingMLPackage createPkg() throws Exception {

    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
   
    NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
    ndp.setContents((Numbering)XmlUtils.unmarshalString(numberingXml));
   
    wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
   
    wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setJaxbElement((Styles)XmlUtils.unmarshalString(stylesXml));
   
    return wordMLPackage;
  }
View Full Code Here

Examples of org.docx4j.openpackaging.packages.WordprocessingMLPackage

  //@Test
  public  void testTblIndentInheritance() throws Exception {
   
    boolean save = true;
   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    wordMLPackage.getMainDocumentPart().setJaxbElement(
        (Document)XmlUtils.unmarshalString(table1XML));   
   
   
      FOSettings foSettings = Docx4J.createFOSettings();
    foSettings.setWmlPackage(wordMLPackage);
   
    OutputStream os = null;
    if (save) {
     
      os = new FileOutputStream(new File(System.getProperty("user.dir") + "/OUT_testTblIndentInheritance.pdf"));
      wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_testTblIndentInheritance.docx"));
    } else {
      // want the fo document as the result.
      foSettings.setApacheFopMime(FOSettings.INTERNAL_FO_MIME);
     
      // exporter writes to an OutputStream.   
View Full Code Here

Examples of org.docx4j.openpackaging.packages.WordprocessingMLPackage

  @Ignore
  public  void testTblIndentOnCentredTable() throws Exception {
   
    boolean save = true;
   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    wordMLPackage.getMainDocumentPart().setJaxbElement(
        (Document)XmlUtils.unmarshalString(table1XML));   
   
   
      FOSettings foSettings = Docx4J.createFOSettings();
    foSettings.setWmlPackage(wordMLPackage);
   
    OutputStream os = null;
    if (save) {
     
      os = new FileOutputStream(new File(System.getProperty("user.dir") + "/OUT_testTblIndentOnCentredTable.pdf"));
      wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_testTblIndentOnCentredTable.docx"));
    } else {
      // want the fo document as the result.
      foSettings.setApacheFopMime(FOSettings.INTERNAL_FO_MIME);
     
      // exporter writes to an OutputStream.   
View Full Code Here

Examples of org.docx4j.openpackaging.packages.WordprocessingMLPackage

  @Test
  @Ignore
  public void testTblStyle_AllSilent() throws Exception {
   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    wordMLPackage.getMainDocumentPart().setContents(
        (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
    wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
        (Styles)XmlUtils.unmarshalString(styles_no_font_sz) );

    setSetting(wordMLPackage, OVERRIDE);

    wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
   
    // NB createVirtualStylesForDocDefaults() puts 10pt there, if nothing is specified!
    // So we need to delete that!
    wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().createVirtualStylesForDocDefaults();
    Style dd = wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getStyleById("DocDefaults");
    dd.getRPr().setSz(null);
    dd.getRPr().setSzCs(null);
   
    ParagraphStylesInTableFix.process(wordMLPackage);
   
View Full Code Here

Examples of org.docx4j.openpackaging.packages.WordprocessingMLPackage

 
  @Test
  @Ignore
  public void testTblStyle_BasedOnNormal() throws Exception {
   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    wordMLPackage.getMainDocumentPart().setContents(
        (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
    wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
        (Styles)XmlUtils.unmarshalString(styles_in_basedOn_Normal) );
   
    // Use our style!
    List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true);
    PPr ppr = Context.getWmlObjectFactory().createPPr();
    ((P)xpathResults.get(0)).setPPr(ppr);
    PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle();
    ps.setVal("testStyle");
    ppr.setPStyle(ps);
   
    setSetting(wordMLPackage, OVERRIDE);

    wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
   
    ParagraphStylesInTableFix.process(wordMLPackage);
   
//    // Revert style and save:
//    ppr.setPStyle(ps); // doesn't work - wrong ref!
//    wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
   
    Style ours = null;
    for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
      if ("testStyle-TableGrid-BR".equals(s.getStyleId())) {
        ours = s;
        break;
      }
    }
View Full Code Here

Examples of org.docx4j.openpackaging.packages.WordprocessingMLPackage

  @Test
  @Ignore
  public void testTblStyle_BasedOn_Normal11() throws Exception {
   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    wordMLPackage.getMainDocumentPart().setContents(
        (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
    wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
        (Styles)XmlUtils.unmarshalString(styles_basedOn_Normal) );
   
    // Use our style!
    List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true);
    PPr ppr = Context.getWmlObjectFactory().createPPr();
    ((P)xpathResults.get(0)).setPPr(ppr);
    PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle();
    ps.setVal("testStyle");
    ppr.setPStyle(ps);
   
    setSetting(wordMLPackage, OVERRIDE);

    wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
   
    ParagraphStylesInTableFix.process(wordMLPackage);
   
//    // Revert style and save:
//    ppr.setPStyle(ps); // doesn't work - wrong ref!
//    wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
   
    Style ours = null;
    for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
      if ("testStyle-TableGrid-BR".equals(s.getStyleId())) {
        ours = s;
        break;
      }
    }
View Full Code Here

Examples of org.docx4j.openpackaging.packages.WordprocessingMLPackage

   
    // Load the docx
    String inputfilepath = System.getProperty("user.dir")
        + "/src/test/java/org/docx4j/model/listnumbering/article-section-isLgl.docx";             
     
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
   
   
    testNumbering(wordMLPackage);
  }
View Full Code Here

Examples of org.docx4j.openpackaging.packages.WordprocessingMLPackage

   
    // Load the docx
    String inputfilepath = System.getProperty("user.dir")
        + "/src/test/java/org/docx4j/model/listnumbering/article-section-NotIsLgl.docx";             
     
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
   
   
    testNumbering(wordMLPackage);
  }
View Full Code Here

Examples of org.docx4j.openpackaging.packages.WordprocessingMLPackage

  public static void main(String[] args) throws Exception {
   
       
    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) );
      System.out.println("Saved " + filename);
    }
           
  }
View Full Code Here

Examples of org.docx4j.openpackaging.packages.WordprocessingMLPackage

    } catch (IllegalArgumentException e) {
      inputfilepath = System.getProperty("user.dir")
          + "/sample-docs/word/sample-docx.docx";
    }

    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
        .load(new java.io.File(inputfilepath));
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();

    // Uncomment to see the raw XML
    //System.out.println(XmlUtils.marshaltoString(documentPart.getJaxbElement(), true, true));

    org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document) documentPart
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.