Package org.docx4j.openpackaging.packages

Examples of org.docx4j.openpackaging.packages.PresentationMLPackage


  public PresentationMLPackage createSmartArtPkg(
      SlideSizesWellKnown sz, boolean landscape,
      Document xml) throws Exception {
           
    // Create skeletal package, including a MainPresentationPart and a SlideLayoutPart
    PresentationMLPackage pMLPackage = PresentationMLPackage.createPackage(sz, landscape);
   
    // Need references to these parts to create a slide
    // Please note that these parts *already exist* - they are
    // created by createPackage() above.  See that method
    // for instruction on how to create and add a part.
    MainPresentationPart pp = (MainPresentationPart)pMLPackage.getParts().getParts().get(
        new PartName("/ppt/presentation.xml"));   
    SlideLayoutPart layoutPart = (SlideLayoutPart)pMLPackage.getParts().getParts().get(
        new PartName("/ppt/slideLayouts/slideLayout1.xml"));
   
    // OK, now we can create a slide
    SlidePart slidePart = pMLPackage.createSlidePart(pp, layoutPart,
        new PartName("/ppt/slides/slide1.xml"));
               
    // Layout part
    DiagramLayoutPart layout = new DiagramLayoutPart(new PartName("/ppt/diagrams.layout1.xml"));
    layout.setJaxbElement(diagramLayoutObj);

    DiagramColorsPart colors = new DiagramColorsPart(new PartName("/ppt/diagrams.colors1.xml"));
    colors.unmarshal("colorsDef-accent1_2.xml");
    //colors.CreateMinimalContent("mycolors");
   
    DiagramStylePart style = new DiagramStylePart(new PartName("/ppt/diagrams.quickStyle1.xml"));
    style.unmarshal("quickStyle-simple1.xml");
    //style.CreateMinimalContent("mystyle");
   
    // DiagramDataPart
    DiagramDataPart data = new DiagramDataPart(new PartName("/ppt/diagrams.data1.xml"));
    data.setPackage(pMLPackage); // otherwise we need to pass pkg around
    data.setJaxbElement( createDiagramData(data, xml) );
   
    String layoutRelId = slidePart.addTargetPart(layout).getId();
    String dataRelId = slidePart.addTargetPart(data).getId();
    String colorsRelId = slidePart.addTargetPart(colors).getId();
    String styleRelId = slidePart.addTargetPart(style).getId();
   
    // Create and add graphicFrame for SmartArt
    Presentation.SldSz tmpSldSz = pMLPackage.getMainPresentationPart().getJaxbElement().getSldSz();
   
    CTGraphicalObjectFrame graphicFrame = createSmartArt( layoutRelId,  dataRelId, colorsRelId,  styleRelId,
        ""+(tmpSldSz.getCx()-200000), ""+(tmpSldSz.getCy()-1000000) );
        // A bit smaller, so we can have a margin around the edge

View Full Code Here


            "org/docx4j/openpackaging/parts/DrawingML/DiagramLayoutTree4AlgHier.xslt")));
   
    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

    // and see what content type is set on that.
    // But the following (well known locations) will do for now.
    if (parts.get("/word/document.xml")!=null) {
      packageResult = new  WordprocessingMLPackage(ctm);
    } else if (parts.get("/ppt/presentation.xml")!=null) {
      packageResult = new  PresentationMLPackage(ctm);
    } else {
      throw new Docx4JException("Unrecognised package");
    }
    log.info("Creating " + packageResult.getClass().getName() );
   
View Full Code Here

   
   
    // A pptx containing all shapes, created using the AutoShapes sample
    String inputfilepath = System.getProperty("user.dir") + "/sample-docs/pptx/AutoShapes.pptx";
   
    PresentationMLPackage presentationMLPackage =
      (PresentationMLPackage)OpcPackage.load(new java.io.File(inputfilepath));

    int slideCount = presentationMLPackage.getMainPresentationPart().getSlideCount();
   
    for (int i=0; i<slideCount; i++) {
   
      System.out.println("\n Slide " + i);
      convert( presentationMLPackage.getMainPresentationPart().getSlide(i) );
    }

    presentationMLPackage.save(
        new File(System.getProperty("user.dir") + "/OUT_ShapesPresetToCustom.pptx"));
  }
View Full Code Here

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

    String inputfilepath = System.getProperty("user.dir") + "/sample-docs/pptx.pptx";
   
    PresentationMLPackage presentationMLPackage =
      (PresentationMLPackage)OpcPackage.load(new java.io.File(inputfilepath));
   
    System.out.println("\n\n saving .. \n\n");
    String outputfilepath = System.getProperty("user.dir") + "/sample-docs/pptx-out.pptx";
    presentationMLPackage.save(new java.io.File(outputfilepath));

    System.out.println("\n\n done .. \n\n");
   
 
View Full Code Here

        || pkgContentType.equals(ContentTypes.PRESENTATIONML_TEMPLATE)
        || pkgContentType.equals(ContentTypes.PRESENTATIONML_TEMPLATE_MACROENABLED)
        || pkgContentType.equals(ContentTypes.PRESENTATIONML_MACROENABLED)
        || pkgContentType.equals(ContentTypes.PRESENTATIONML_SLIDESHOW) ) {
      log.info("Detected PresentationMLPackage package ");
      p = new PresentationMLPackage(this);
      return p;
    } else if (pkgContentType.equals(ContentTypes.SPREADSHEETML_WORKBOOK)
        || pkgContentType.equals(ContentTypes.SPREADSHEETML_WORKBOOK_MACROENABLED)
        || pkgContentType.equals(ContentTypes.SPREADSHEETML_TEMPLATE)
        || pkgContentType.equals(ContentTypes.SPREADSHEETML_TEMPLATE_MACROENABLED) ) {
View Full Code Here

    String firstValue  = String.valueOf(rand.nextInt(99));
    String secondValue = String.valueOf(rand.nextInt(99));
   
    // Open the PPT template file
    PresentationMLPackage ppt = (PresentationMLPackage) OpcPackage
      .load(new java.io.File(inputfilepath));

    /*
     * Get the Chart object and update the values. Afterwards, we'll update
     * the associated spreadsheet so that the data is synchronized.
     */
    Chart chart = (Chart) ppt.getParts().get(new PartName(chartPartName));
   
    List<Object> objects = chart.getJaxbElement().getChart().getPlotArea()
        .getAreaChartOrArea3DChartOrLineChart();
   
    for (Object object : objects) {
     
      if (object instanceof CTBarChart) {

        List<CTBarSer> ctBarSers = ((CTBarChart) object).getSer();
       
        for (CTBarSer ctBarSer : ctBarSers)
        {
          List<CTNumVal> ctNumVals = ctBarSer.getVal().getNumRef().getNumCache().getPt();
          for (CTNumVal ctNumVal : ctNumVals)
          {
            System.out.println("ctNumVal Val BEFORE: " + ctNumVal.getV());
            if (ctNumVal.getIdx() == 0) {
              ctNumVal.setV(firstValue);
            }
            else if (ctNumVal.getIdx() == 1) {
              ctNumVal.setV(secondValue)
            }
            System.out.println("ctNumVal Val AFTER: " + ctNumVal.getV());
          }
        }
      }
    }
       
    /*
     * Get the spreadsheet and find the cell values that need to be updated
     */
   
    EmbeddedPackagePart epp  = (EmbeddedPackagePart) ppt
      .getParts().get(new PartName(xlsPartName));
   
    if (epp==null) {
      throw new Docx4JException("Could find EmbeddedPackagePart: " + xlsPartName);
    }
   
    InputStream is = BufferUtil.newInputStream(epp.getBuffer());
   
    SpreadsheetMLPackage spreadSheet = (SpreadsheetMLPackage) SpreadsheetMLPackage.load(is);

    Map<PartName,Part> partsMap = spreadSheet.getParts().getParts();    
    Iterator<Entry<PartName, Part>> it = partsMap.entrySet().iterator();

    while(it.hasNext()) {
      Map.Entry<PartName, Part> pairs = it.next();
     
      if (partsMap.get(pairs.getKey()) instanceof WorksheetPart) {
       
        WorksheetPart wsp = (WorksheetPart) partsMap.get(pairs.getKey()) ;
       
        List<Row> rows = wsp.getJaxbElement().getSheetData().getRow();

        for (Row row : rows) {
          List<Cell> cells = row.getC();
          for (Cell cell : cells)
          {
            if (cell.getR().equals("B2") && cell.getV() != null) {
              System.out.println("B2 CELL VAL: " + cell.getV());
              // change the B2 cell value
              cell.setT(STCellType.STR);
              cell.setV(firstValue);
            }
            else if (cell.getR().equals("B3") && cell.getV() != null) {
              System.out.println("B3 CELL VAL: " + cell.getV());
              // Change the B3 cell value
              cell.setT(STCellType.STR);
              cell.setV(secondValue);
            }
          }         
        }
      }
    }

    /*
     * Convert the Spreadsheet to a binary format, set it on the
     * EmbeddedPackagePart, add it back onto the deck and save to a file.
     * 
     */   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
   
    SaveToZipFile saver = new SaveToZipFile(spreadSheet);

    saver.save(baos);
    epp.setBinaryData(baos.toByteArray());

    // Write the new file to disk
    ppt.save(new java.io.File(outputfilepath));

    System.out.println("\n\n done .. saved " + outputfilepath);
  }
View Full Code Here

    // Where will we save our new .ppxt?
    String outputfilepath = System.getProperty("user.dir") + "/sample-docs/pptx/AutoShapes.pptx";
   
    // Create skeletal package
    PresentationMLPackage presentationMLPackage = PresentationMLPackage.createPackage();
   
    MainPresentationPart pp = (MainPresentationPart)presentationMLPackage.getParts().getParts().get(
        new PartName("/ppt/presentation.xml"));
   
    SlideLayoutPart layoutPart = (SlideLayoutPart)presentationMLPackage.getParts().getParts().get(
        new PartName("/ppt/slideLayouts/slideLayout1.xml"));
   
    boolean noLine = false;
   
    /* ST_ShapeType has 203 values
     *
     * Create a slide for each shape */
    int i = 1
    for (STShapeType st : STShapeType.values() ) {
   
      System.out.println("Adding slide for shape: " + st.value() );
     
      SlidePart slidePart = createSlidePart(pp, layoutPart, i);
     
      // Create and add shapes
      Shape title = ((Shape)XmlUtils.unmarshalString(
          getSlideTitle(st.value()), Context.jcPML) );
      slidePart.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(title);
     
     
      Shape sample = ((Shape)XmlUtils.unmarshalString(
          getPresetShape(st.value(), noLine), Context.jcPML) );
      slidePart.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(sample);
     
      i++;
    }
    // All done: save it
    presentationMLPackage.save(new java.io.File(outputfilepath));

    System.out.println("\n\n done .. saved " + outputfilepath);
   
 
View Full Code Here

//    String inputfilepath = System.getProperty("user.dir") + "/sample-docs/pptx/lines.pptx";

      // Where to save images
      SvgExporter.setImageDirPath(System.getProperty("user.dir") + "/sample-docs/pptx/");
   
    PresentationMLPackage presentationMLPackage =
      (PresentationMLPackage)PresentationMLPackage.load(new java.io.File(inputfilepath));   
   
    // TODO - render slides in document order!
    Iterator partIterator = presentationMLPackage.getParts().getParts().entrySet().iterator();
      while (partIterator.hasNext()) {
       
          Map.Entry pairs = (Map.Entry)partIterator.next();
         
          Part p = (Part)pairs.getValue();
View Full Code Here

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

    PresentationMLPackage pMLPackage =
      (PresentationMLPackage)OpcPackage.load(new java.io.File(inputfilepath));

    SlidePart slide = (SlidePart)pMLPackage.getParts().get(new PartName("/ppt/slides/slide1.xml") );
   
    new TraversalUtil(slide.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame(),

    new Callback() {
View Full Code Here

TOP

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

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.