Package org.docx4j.openpackaging.packages

Examples of org.docx4j.openpackaging.packages.WordprocessingMLPackage$FilterSettings


      }
    }

  public static void main(String[] args) throws Exception {
    String filepath = System.getProperty("user.dir") + "/sample-docs/word/FontEmbedded.docx";   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(filepath));
   
    wordMLPackage.getMainDocumentPart().getFontTablePart().processEmbeddings();
  }
View Full Code Here


   * @throws Exception
   */
  public Inline createImageInline(String filenameHint, String altText,
      int id1, int id2, boolean link) throws Exception {
       
        WordprocessingMLPackage wmlPackage = ((WordprocessingMLPackage) this.getPackage());
   
    List<SectionWrapper> sections = wmlPackage.getDocumentModel().getSections();
        PageDimensions page = sections.get(sections.size() - 1).getPageDimensions();
   
    CxCy cxcy = CxCy.scale(imageInfo, page);
        return createImageInline(filenameHint, altText,
View Full Code Here

       
        final java.io.File targetFile = new java.io.File(System.getProperty("user.dir") + "/Generated.docx");
        final FileOutputStream targetFos = new FileOutputStream(targetFile);

        final DocxService docxService = new DocxService();
        final WordprocessingMLPackage docxTemplate = docxService.loadPackage(docxTemplateIs);
        docxService.merge(html, docxTemplate, targetFos, MatchingPolicy.LAX);
       
        System.out.println(targetFile.getAbsolutePath());
    }
View Full Code Here

              <wantspam>false</wantspam>
            </misc>
        </invoice>
     */
   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));       

//    System.out.println(
//    XmlUtils.marshaltoString(
//        wordMLPackage.getMainDocumentPart().getJaxbElement(), true) );
   
    // Process conditionals and repeats
    OpenDoPEHandler odh = new OpenDoPEHandler(wordMLPackage);
    odh.preprocess();

    // Since the JAXB binding stuff seems to remember
    // old artifacts, we'll first create a 'clean' object here
    // from something we've marshalled to. 
    org.w3c.dom.Document xmlNode = XmlUtils.marshaltoW3CDomDocument(
        wordMLPackage.getMainDocumentPart().getJaxbElement());       
    Binder<Node> binder = Context.jc.createBinder();
    Object jaxbElement =  (org.docx4j.wml.Document) binder.unmarshal(xmlNode);
   
    // Test (1)
    // Before processing, the table contains 2 rows
    // (a header row, and 1 for content).
    // Now it should contain 4 rows.
       
    List<Object> list = XmlUtils.getJAXBNodesViaXPath(binder, jaxbElement,
        "//w:tr", false );   
    int count = list.size();
   
    assertTrue("expected 4 rows but got " + count, count==4 );
   
    // 3 cells should contain 'apples', but I don't test that
   
    // Test (2)
    // Conditions
    // <includeBankDetails>true</includeBankDetails>
    list = XmlUtils.getJAXBNodesViaXPath(binder, jaxbElement,
        "//w:r[w:t[contains(text(),'Bank')]]",
        false );
    count = list.size();
    assertTrue("expected 1 run but got " + count, count==1 );

    // <wantspam>false</wantspam>
    list = XmlUtils.getJAXBNodesViaXPath(binder, jaxbElement,
        "//w:r[w:t[contains(text(),'left out')]]",
        false );
    count = list.size();
    assertTrue("expected 0 runs but got " + count, count==0 );
   
    // Apply the bindings
    AtomicInteger bookmarkId = odh.getNextBookmarkId();
    BindingHandler bh = new BindingHandler(wordMLPackage);
    bh.setStartingIdForNewBookmarks(bookmarkId);
    bh.applyBindings(wordMLPackage.getMainDocumentPart());
   

    // create a 'clean' object again ..   
    xmlNode = XmlUtils.marshaltoW3CDomDocument(
        wordMLPackage.getMainDocumentPart().getJaxbElement());       
    binder = Context.jc.createBinder();
    jaxbElement =  (org.docx4j.wml.Document) binder.unmarshal(xmlNode);
   
    // Test (3)
    list = XmlUtils.getJAXBNodesViaXPath(binder, jaxbElement,
View Full Code Here

              </country>
            </countries>
          </root>
     */
   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));       

//    System.out.println(
//    XmlUtils.marshaltoString(
//        wordMLPackage.getMainDocumentPart().getJaxbElement(), true) );
   
    // Process conditionals and repeats
    OpenDoPEHandler odh = new OpenDoPEHandler(wordMLPackage);
    odh.preprocess();

    // Since the JAXB binding stuff seems to remember
    // old artifacts, we'll first create a 'clean' object here
    // from something we've marshalled to.     
    org.w3c.dom.Document xmlNode = XmlUtils.marshaltoW3CDomDocument(
        wordMLPackage.getMainDocumentPart().getJaxbElement());       
    Binder<Node> binder = Context.jc.createBinder();
    Object jaxbElement =  (org.docx4j.wml.Document) binder.unmarshal(xmlNode);
   
    // Test (1)
    // After processing, we should have 3 tables
       
    List<Object> list = XmlUtils.getJAXBNodesViaXPath(binder, jaxbElement,
        "//w:tbl", false );   
    int count = list.size();   
    assertTrue("expected 3 tables but got " + count, count==3 );
   
    // First table has 2 rows
    list = XmlUtils.getJAXBNodesViaXPath(binder, jaxbElement,
        "/descendant::w:tbl[1]/*[local-name()='sdt' or local-name()='tr']" , false )
//    for (Object o : list){     
//      System.out.println(XmlUtils.marshaltoString(o, true));     
//    }
    count = list.size();   
    assertTrue("expected 2 rows but got " + count, count==2 );   

    // Second table has 3 rows
    list = XmlUtils.getJAXBNodesViaXPath(binder, jaxbElement,
        "/descendant::w:tbl[2]/*[local-name()='sdt' or local-name()='tr']" , false )
    count = list.size();   
    assertTrue("expected 3 rows but got " + count, count==3 );   

    // Third table has 4 rows
    list = XmlUtils.getJAXBNodesViaXPath(binder, jaxbElement,
        "/descendant::w:tbl[3]/*[local-name()='sdt' or local-name()='tr']" , false )
    count = list.size();   
    assertTrue("expected 4 rows but got " + count, count==4 );   
   
    // Apply the bindings
    AtomicInteger bookmarkId = odh.getNextBookmarkId();
    BindingHandler bh = new BindingHandler(wordMLPackage);
    bh.setStartingIdForNewBookmarks(bookmarkId);
    bh.applyBindings(wordMLPackage.getMainDocumentPart());

    // create a 'clean' object again ..   
    xmlNode = XmlUtils.marshaltoW3CDomDocument(
        wordMLPackage.getMainDocumentPart().getJaxbElement());       
    binder = Context.jc.createBinder();
    jaxbElement =  (org.docx4j.wml.Document) binder.unmarshal(xmlNode);
   
    // Test (3)
    // Test that the last w:tc in the last table contains 'P c3 r3'
View Full Code Here

  public void testSmartTag() throws Exception {
   
    String inputfilepath = System.getProperty("user.dir")
      + "/src/test/resources/OpenDoPE/repeat-containing-JAXBElement.docx";
       
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));       

    System.out.println(
    XmlUtils.marshaltoString(
        wordMLPackage.getMainDocumentPart().getJaxbElement(), true) );
   
    // Process conditionals and repeats
    OpenDoPEHandler odh = new OpenDoPEHandler(wordMLPackage);
    odh.preprocess();

    XmlUtils.marshaltoString(
        wordMLPackage.getMainDocumentPart().getJaxbElement(), true) ;
   
  }
View Full Code Here

  @Test
  public void testTblStyle_BasedOnNormal() throws Exception {
   
    // Compat setting says Paragraph style overrides table style   
 
    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)// table style should get overridden
 
    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

  @Test
  public void testTblStyle_BasedOn_Normal12() throws Exception {
   
    // Compat setting says Paragraph style overrides table style   
 
    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

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

  private static org.docx4j.wml.ObjectFactory wmlObjectFactory = Context.getWmlObjectFactory();

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

    P p = createNumberedP("ChapterLevel1", 12, 0);
    mdp.getContent().add(p);
    Assert.assertEquals("1", Emulator.getNumber(wordMLPackage, p.getPPr()).getNumString());
   
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.packages.WordprocessingMLPackage$FilterSettings

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.