Package org.docx4j.openpackaging.io

Examples of org.docx4j.openpackaging.io.SaveToZipFile


  private static Logger log = LoggerFactory.getLogger(SaveToVFSZipFile.class);       
 
  private SaveToZipFile _saveToZipFile;
 
  public SaveToVFSZipFile(OpcPackage p) {
    _saveToZipFile = new SaveToZipFile(p);
  }
View Full Code Here


   
    System.out.println(XmlUtils.marshaltoString(wmlPackage.getMainDocumentPart().getJaxbElement(), true, true));

    // Save it
    if (save) {
      SaveToZipFile saver = new SaveToZipFile(wmlPackage);
      saver.save(System.getProperty("user.dir") + "/OUT_VariablePrepare.docx");
      System.out.println("Saved");
    }
  }
View Full Code Here

    WordprocessingMLPackage pkgIn = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
   
    FromVariableReplacement migrator = new FromVariableReplacement();
    WordprocessingMLPackage pkgOut = migrator.migrate(pkgIn);
   
    SaveToZipFile saver = new SaveToZipFile(pkgOut);
    saver.save(outputfilepath);
   
  }
View Full Code Here

    WordprocessingMLPackage pkgIn = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
   
    FromMergeFields migrator = new FromMergeFields();
    WordprocessingMLPackage pkgOut = migrator.migrate(pkgIn);
   
    SaveToZipFile saver = new SaveToZipFile(pkgOut);
    saver.save(outputfilepath);
   
  }
View Full Code Here

    }
   
    // Create WordprocessingMLPackage target, by cloning
    OpcPackage result = null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    SaveToZipFile saver = new SaveToZipFile(input);
    saver.save(baos);
    byte[] template = baos.toByteArray();
    WordprocessingMLPackage target = WordprocessingMLPackage.load(
        new ByteArrayInputStream(template));
   
   
View Full Code Here

    CreatePptxWithSmartArt creatorPptx = new CreatePptxWithSmartArt(diagramLayoutObj, layoutTreeCreatorXslt, layoutTree2DiagramDataXslt);
   

    PresentationMLPackage pkg = creatorPptx.createSmartArtPkg(SlideSizesWellKnown.A3, true, doc);
   
    SaveToZipFile saver = new SaveToZipFile(pkg);
    saver.save(new File(System.getProperty("user.dir")+ "/OUT.pptx"  ) );
    System.out.println("Done!");
  }
View Full Code Here

      if (method==null) throw new NoSuchMethodException();
     
      WordprocessingMLPackage resultPkg = (WordprocessingMLPackage)method.invoke(null, wmlPkgList);

      if (save) {   
        SaveToZipFile saver = new SaveToZipFile(resultPkg);
        saver.save(outputfilepath);
        System.out.println("Generated " + outputfilepath);
      } else {
        String result = XmlUtils.marshaltoString(resultPkg.getMainDocumentPart().getJaxbElement(), true, true);
        System.out.println(result);       
      }
View Full Code Here

    timingSummary.append("\nOpenDoPEIntegrity: " + (endTime-startTime));
   
    System.out.println(
        XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true)
        );   
    SaveToZipFile saver = new SaveToZipFile(wordMLPackage);
    saver.save(filepathprefix + "_preprocessed.docx");
    System.out.println("Saved: " + filepathprefix + "_preprocessed.docx");
   
    // Apply the bindings
    BindingHandler.setHyperlinkStyle("Hyperlink");           
    startTime = System.currentTimeMillis();
   
    AtomicInteger bookmarkId = odh.getNextBookmarkId();
    BindingHandler bh = new BindingHandler(wordMLPackage);
    bh.setStartingIdForNewBookmarks(bookmarkId);
    bh.applyBindings(wordMLPackage.getMainDocumentPart());
   
    endTime = System.currentTimeMillis();
    timingSummary.append("\nBindingHandler.applyBindings: " + (endTime-startTime));
    String bound = XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true);
    System.out.println(
        );
    saver.save(filepathprefix + "_bound.docx");
    System.out.println("Saved: " + filepathprefix + "_bound.docx");
   
    // process altChunk
    if (bound.contains("altChunk")) {
      try {
        // Use reflection, so docx4j can be built
        // by users who don't have the MergeDocx utility
        Class<?> documentBuilder = Class
            .forName("com.plutext.merge.ProcessAltChunk");
        // Method method = documentBuilder.getMethod("merge",
        // wmlPkgList.getClass());
        Method[] methods = documentBuilder.getMethods();
        Method processMethod = null;
        for (int j = 0; j < methods.length; j++) {
  //        log.debug(methods[j].getName());
          if (methods[j].getName().equals("process")) {
            processMethod = methods[j];
          }
        }
        if (processMethod == null )
          throw new NoSuchMethodException();
       
        startTime = System.currentTimeMillis();
       
        wordMLPackage = (WordprocessingMLPackage) processMethod.invoke(null,
            wordMLPackage);
 
        endTime = System.currentTimeMillis();
        timingSummary.append("\nBindingHandler.applyBindings: " + (endTime-startTime));
        System.out.println(
            XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true)
            );
        saver.save(filepathprefix + "_altChunksMerged.docx");
        System.out.println("Saved: " + filepathprefix + "_altChunksMerged.docx");
 
       
      } catch (ClassNotFoundException e) {
      } catch (NoSuchMethodException e) {
      } catch (Exception e) {
        throw new Docx4JException("Problem processing w:altChunk", e);
     
    }
   
    // Either demonstrate reverter, or stripping of controls;
    // you can't do both. So comment out one or the other.
//    reverter(inputfilepath, filepathprefix + "_bound.docx");
//   
    // Strip content controls
    startTime = System.currentTimeMillis();
    RemovalHandler rh = new RemovalHandler();
    rh.removeSDTs(wordMLPackage, Quantifier.ALL);
    endTime = System.currentTimeMillis();
    timingSummary.append("\nRemovalHandler: " + (endTime-startTime));

    saver.save(filepathprefix + "_stripped.docx");
    System.out.println("Saved: " + filepathprefix + "_stripped.docx");
   
    System.out.println(timingSummary);
 
View Full Code Here

        WordprocessingMLPackage.load(new java.io.File(inputfilepath)),
        instancePkg);
   
    System.out.println("reverted? " + reverter.revert() );
   
    SaveToZipFile saver = new SaveToZipFile(instancePkg);
    saver.save(filepathprefix + "_reverted.docx");
    System.out.println("Saved: " + filepathprefix + "_reverted.docx");
   
  }
View Full Code Here

    Hyperlink h = MainDocumentPart.hyperlinkToBookmark(bookmarkName, "link to bookmark");
    wordMLPackage.getMainDocumentPart().addParagraphOfText("some text").getContent().add(h);
   
    System.out.println( XmlUtils.marshaltoString(p, true)  );
   
    SaveToZipFile saver = new SaveToZipFile(wordMLPackage);
    saver.save(outputfilepath);
  }
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.io.SaveToZipFile

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.