Package org.docx4j.openpackaging.packages

Examples of org.docx4j.openpackaging.packages.WordprocessingMLPackage


  public static void main(String[] args) throws Exception {
   
   
    String inputfilepath = System.getProperty("user.dir") + "/test.docx";
   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
        .load(new java.io.File(inputfilepath));
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
   
    Marshaller marshaller=Context.jc.createMarshaller();
    NamespacePrefixMapperUtils.setProperty(marshaller,
        NamespacePrefixMapperUtils.getPrefixMapper());
   
View Full Code Here


  public static void main(String[] args) throws Exception {
   
   
    String inputfilepath = System.getProperty("user.dir") + "/test.docx";
   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
        .load(new java.io.File(inputfilepath));
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
   
    Marshaller marshaller=Context.jc.createMarshaller();
    NamespacePrefixMapperUtils.setProperty(marshaller,
        NamespacePrefixMapperUtils.getPrefixMapper());
   
View Full Code Here

  }
 
  @Test
  public void testDiffDocx() throws Exception {
   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
   
    for (int i=0; i<testparagraphs.length-1; i++){

      for (int j=0; j<testparagraphs.length; j++){
      //for (int j=i+1; j<testparagraphs.length; j++){
     
        wordMLPackage.getMainDocumentPart().addParagraphOfText("TESTING " + testparagraphs[i]
                + ", " + testparagraphs[j] );
       
        // Test setup
        wordMLPackage.getMainDocumentPart().addParagraphOfText("first:");
        P pl = Differencer.loadParagraph(BASE_DIR + testparagraphs[i]);
        wordMLPackage.getMainDocumentPart().addObject(pl);
       
        wordMLPackage.getMainDocumentPart().addParagraphOfText("second:");
        P pr = Differencer.loadParagraph(BASE_DIR + testparagraphs[j]);
        wordMLPackage.getMainDocumentPart().addObject(pr);
       
        // Result format       
        JAXBContext jc = Context.jc;
        javax.xml.bind.util.JAXBResult result = new javax.xml.bind.util.JAXBResult(jc );
   
        // Run the diff
        Differencer pd = new Differencer();       
        pd.diff(pl, pr, result, null, null,
            null, null);
       
        try {
          P markedUpP = (org.docx4j.wml.P)result.getResult();
         
          wordMLPackage.getMainDocumentPart().addParagraphOfText("result:");
          wordMLPackage.getMainDocumentPart().addObject(markedUpP);
        } catch (RuntimeException e) {
          String msg = "failed to apply stylesheet to pre-processed! "
            + testparagraphs[i] + ", " + testparagraphs[j];
          System.out.println(msg);
          e.printStackTrace();
          wordMLPackage.getMainDocumentPart().addParagraphOfText(msg);
         
          StreamResult err = new StreamResult(System.out);
          pd.diff(pl, pr, err, null, null,
              null, null);
         
        }
       
        // Compare no pre-processor
        result = new javax.xml.bind.util.JAXBResult(jc );
        pd.diff(pl, pr, result, null, null,
            null, null);       
        try {
          P markedUpPsimple = (org.docx4j.wml.P)result.getResult();        
          wordMLPackage.getMainDocumentPart().addParagraphOfText("no preprocessing:");
          wordMLPackage.getMainDocumentPart().addObject(markedUpPsimple);       
        } catch (RuntimeException e) {
          String msg = "failed to apply stylesheet to naive! "
            + testparagraphs[i] + ", " + testparagraphs[j];
          System.out.println(msg);
          e.printStackTrace();
          wordMLPackage.getMainDocumentPart().addParagraphOfText(msg);
         
          StreamResult err = new StreamResult(System.out);
          pd.diff(pl, pr, err, null, null,
              null, null);
         
        }
      }
    }

    // Now save it
    wordMLPackage.save(new java.io.File(System.getProperty("java.io.tmpdir")
            + "/diff.docx") );
   
   
  }
View Full Code Here

   */
  @Test
  public  void testTblHeaderOne() throws Exception {
   
    String inputfilepath = System.getProperty("user.dir") + "/src/test/resources/tables/tblHeaderTestOne.docx";
    WordprocessingMLPackage wordMLPackage= WordprocessingMLPackage.load(new java.io.File(inputfilepath))
   
      FOSettings foSettings = Docx4J.createFOSettings();
    foSettings.setWmlPackage(wordMLPackage);
   
    // want the fo document as the result.
View Full Code Here

   */
  @Test
  public  void testTblHeaderTwo() throws Exception {
   
    String inputfilepath = System.getProperty("user.dir") + "/src/test/resources/tables/tblHeaderTestTwo.docx";
    WordprocessingMLPackage wordMLPackage= WordprocessingMLPackage.load(new java.io.File(inputfilepath))
   
      FOSettings foSettings = Docx4J.createFOSettings();
    foSettings.setWmlPackage(wordMLPackage);
   
    // want the fo document as the result.
View Full Code Here

    return test( documentXml,  styleXml,  EXPECTED_RESULT);
  }
 
  protected WordprocessingMLPackage test(String documentXml, String styleXml,  int expectedResult) throws Exception {

    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    wordMLPackage.getMainDocumentPart().setContents(
        (Document)XmlUtils.unmarshalString(documentXml) );
    wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
        (Styles)XmlUtils.unmarshalString(styleXml) );
   
    setSetting(wordMLPackage, OVERRIDE)// table style should not get overridden

    /* Where Normal is basedOn our DocDefaults style, 
     * Word *does* override the table style!
     *
     * It doesn't if there is just a normal DocDefaults element
     * which sets the font size.  And that is what we should be testing here.
     *
     * So save the docx
     *
     * Note that createVirtualStylesForDocDefaults() puts 10pt there, if nothing is specified,
     * so we save the docx here before that method has run.
     */
    wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
//    this.saveDocx(wordMLPackage, null);
   
    ParagraphStylesInTableFix.process(wordMLPackage);
   
//    // Now remove the style, and save the docx, to check in Word
View Full Code Here

   

    // paragraph
     
    // NB, to implement this case properly, Word needs <w10:wrap type="square"/>
      WordprocessingMLPackage wordMLPackage = createTextBoxDocx(true, "position:absolute;margin-left:0;margin-top:0;width:186pt;height:110.25pt;z-index:-251657216;visibility:visible;mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:center;mso-position-horizontal-relative:text;mso-position-vertical:absolute;mso-position-vertical-relative:text;mso-width-percent:400;mso-height-percent:200;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top" );
      execute( wordMLPackage);
  }
View Full Code Here

  }

  public static void notWrappedParagraph(String[] args) throws Exception {
   
    // NB, to implement this case properly, Word needs <w10:wrap type="square"/>
      WordprocessingMLPackage wordMLPackage = createTextBoxDocx(true, "position:absolute;margin-left:0;margin-top:0;width:186pt;height:110.25pt;z-index:-251657216;visibility:visible;mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:center;mso-position-horizontal-relative:text;mso-position-vertical:absolute;mso-position-vertical-relative:text;mso-width-percent:400;mso-height-percent:200;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top" );
      execute( wordMLPackage);
  }
View Full Code Here

  }
 
  public static void notWrappedPageTop(String[] args) throws Exception {
     
    // NB, to implement this case properly, Word needs <w10:wrap anchory="page"/>
      WordprocessingMLPackage wordMLPackage = createTextBoxDocx(true, "position:absolute;margin-left:0;margin-top:0;width:186pt;height:110.25pt;z-index:-251657216;visibility:visible;mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:center;mso-position-horizontal-relative:text;mso-position-vertical:top;mso-position-vertical-relative:page;mso-width-percent:400;mso-height-percent:200;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top" );
      execute( wordMLPackage);
  }
View Full Code Here

      execute( wordMLPackage);
  }
 
  public static void notWrappedPageBottom(String[] args) throws Exception {
   
      WordprocessingMLPackage wordMLPackage = createTextBoxDocx(true, "position:absolute;margin-left:0;margin-top:0;width:186pt;height:110.25pt;z-index:-251657216;visibility:visible;mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:center;mso-position-horizontal-relative:text;mso-position-vertical:bottom;mso-position-vertical-relative:page;mso-width-percent:400;mso-height-percent:200;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top"  );
      execute( wordMLPackage);
  }
View Full Code Here

TOP

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

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.