Example #1
0
  /**
   * Adds a picture to the workbook.
   *
   * @param pictureData The bytes of the picture
   * @param format The format of the picture.
   * @return the index to this picture (1 based).
   * @see XSLFPictureData#PICTURE_TYPE_EMF
   * @see XSLFPictureData#PICTURE_TYPE_WMF
   * @see XSLFPictureData#PICTURE_TYPE_PICT
   * @see XSLFPictureData#PICTURE_TYPE_JPEG
   * @see XSLFPictureData#PICTURE_TYPE_PNG
   * @see XSLFPictureData#PICTURE_TYPE_DIB
   */
  public int addPicture(byte[] pictureData, int format) {
    XSLFPictureData img = findPictureData(pictureData);
    POIXMLRelation relDesc = XSLFPictureData.RELATIONS[format];

    if (img == null) {
      int imageNumber = _pictures.size();
      img =
          (XSLFPictureData)
              createRelationship(
                  XSLFPictureData.RELATIONS[format],
                  XSLFFactory.getInstance(),
                  imageNumber + 1,
                  true);
      _pictures.add(img);
      try {
        OutputStream out = img.getPackagePart().getOutputStream();
        out.write(pictureData);
        out.close();
      } catch (IOException e) {
        throw new POIXMLException(e);
      }
      return _pictures.size() - 1;
    } else {
      return _pictures.indexOf(img);
    }
  }
Example #2
0
  /**
   * Create a slide and initialize it from the specified layout.
   *
   * @param layout
   * @return created slide
   */
  @SuppressWarnings("deprecation")
  public XSLFSlide createSlide(XSLFSlideLayout layout) {
    int slideNumber = 256, cnt = 1;
    CTSlideIdList slideList;
    if (!_presentation.isSetSldIdLst()) slideList = _presentation.addNewSldIdLst();
    else {
      slideList = _presentation.getSldIdLst();
      for (CTSlideIdListEntry slideId : slideList.getSldIdArray()) {
        slideNumber = (int) Math.max(slideId.getId() + 1, slideNumber);
        cnt++;
      }
    }

    XSLFSlide slide =
        (XSLFSlide) createRelationship(XSLFRelation.SLIDE, XSLFFactory.getInstance(), cnt);

    CTSlideIdListEntry slideId = slideList.addNewSldId();
    slideId.setId(slideNumber);
    slideId.setId2(slide.getPackageRelationship().getId());

    layout.copyLayout(slide);
    slide.addRelation(layout.getPackageRelationship().getId(), layout);

    PackagePartName ppName = layout.getPackagePart().getPartName();
    slide
        .getPackagePart()
        .addRelationship(
            ppName, TargetMode.INTERNAL, layout.getPackageRelationship().getRelationshipType());

    _slides.add(slide);
    return slide;
  }
Example #3
0
  /** Create a notes master. */
  public void createNotesMaster() {

    _notesMaster =
        (XSLFNotesMaster)
            createRelationship(XSLFRelation.NOTES_MASTER, XSLFFactory.getInstance(), 1);

    CTNotesMasterIdList notesMasterIdList = _presentation.addNewNotesMasterIdLst();
    CTNotesMasterIdListEntry notesMasterId = notesMasterIdList.addNewNotesMasterId();
    notesMasterId.setId(_notesMaster.getPackageRelationship().getId());

    Integer themeIndex = 1;
    List<Integer> themeIndexList = new ArrayList<Integer>();
    for (POIXMLDocumentPart p : getRelations()) {
      if (p instanceof XSLFTheme) {
        themeIndexList.add(XSLFRelation.THEME.getFileNameIndex(p));
      }
    }

    if (!themeIndexList.isEmpty()) {
      Boolean found = false;
      for (Integer i = 1; i <= themeIndexList.size(); i++) {
        if (!themeIndexList.contains(i)) {
          found = true;
          themeIndex = i;
        }
      }
      if (!found) {
        themeIndex = themeIndexList.size() + 1;
      }
    }

    XSLFTheme theme =
        (XSLFTheme) createRelationship(XSLFRelation.THEME, XSLFFactory.getInstance(), themeIndex);
    theme.importTheme(getSlides()[0].getTheme());

    _notesMaster.addRelation(theme.getPackageRelationship().getId(), theme);
    PackagePartName themePackagePartName = theme.getPackagePart().getPartName();
    _notesMaster
        .getPackagePart()
        .addRelationship(
            themePackagePartName,
            TargetMode.INTERNAL,
            theme.getPackageRelationship().getRelationshipType());
  }
Example #4
0
  public XMLSlideShow(OPCPackage pkg) {
    super(pkg);

    try {
      if (getCorePart().getContentType().equals(XSLFRelation.THEME_MANAGER.getContentType())) {
        rebase(getPackage());
      }

      // build a tree of POIXMLDocumentParts, this presentation being the root
      load(XSLFFactory.getInstance());
    } catch (Exception e) {
      throw new POIXMLException(e);
    }
  }
Example #5
0
  /** Create a blank notes slide. */
  private XSLFNotes createNotesSlide(XSLFSlide slide) {

    if (_notesMaster == null) {
      createNotesMaster();
    }

    Integer slideIndex = XSLFRelation.SLIDE.getFileNameIndex(slide);

    XSLFNotes notesSlide =
        (XSLFNotes) createRelationship(XSLFRelation.NOTES, XSLFFactory.getInstance(), slideIndex);

    notesSlide.addRelation(_notesMaster.getPackageRelationship().getId(), _notesMaster);
    PackagePartName notesMasterPackagePartName = _notesMaster.getPackagePart().getPartName();
    notesSlide
        .getPackagePart()
        .addRelationship(
            notesMasterPackagePartName,
            TargetMode.INTERNAL,
            _notesMaster.getPackageRelationship().getRelationshipType());

    slide.addRelation(notesSlide.getPackageRelationship().getId(), notesSlide);
    PackagePartName notesSlidesPackagePartName = notesSlide.getPackagePart().getPartName();
    slide
        .getPackagePart()
        .addRelationship(
            notesSlidesPackagePartName,
            TargetMode.INTERNAL,
            notesSlide.getPackageRelationship().getRelationshipType());

    notesSlide.addRelation(slide.getPackageRelationship().getId(), slide);
    PackagePartName slidesPackagePartName = slide.getPackagePart().getPartName();
    notesSlide
        .getPackagePart()
        .addRelationship(
            slidesPackagePartName,
            TargetMode.INTERNAL,
            slide.getPackageRelationship().getRelationshipType());

    notesSlide.importContent(_notesMaster);

    return notesSlide;
  }