Class XMLSlideShow

All Implemented Interfaces:
Closeable, AutoCloseable, SlideShow<XSLFShape,XSLFTextParagraph>

@Beta public class XMLSlideShow extends POIXMLDocument implements SlideShow<XSLFShape,XSLFTextParagraph>
High level representation of an ooxml slideshow. This is the first object most users will construct whether they are reading or writing a slideshow. It is also the top level object for creating new slides/etc.
  • Constructor Details

    • XMLSlideShow

      public XMLSlideShow()
    • XMLSlideShow

      public XMLSlideShow(OPCPackage pkg)
      Parameters:
      pkg - OPC package
      Throws:
      POIXMLException - a RuntimeException that can be caused by invalid OOXML data
      IllegalStateException - a number of other runtime exceptions can be thrown, especially if there are problems with the input format
    • XMLSlideShow

      public XMLSlideShow(InputStream stream) throws IOException
      Parameters:
      stream - InputStream, which is closed after it is read
      Throws:
      IOException - If reading data from the stream fails
      POIXMLException - a RuntimeException that can be caused by invalid OOXML data
      IllegalStateException - a number of other runtime exceptions can be thrown, especially if there are problems with the input format
    • XMLSlideShow

      public XMLSlideShow(InputStream stream, boolean closeStream) throws IOException
      Parameters:
      stream - InputStream
      closeStream - Whether to close the InputStream
      Throws:
      IOException - If reading data from the stream fails
      POIXMLException - a RuntimeException that can be caused by invalid OOXML data
      IllegalStateException - a number of other runtime exceptions can be thrown, especially if there are problems with the input format
      Since:
      5.2.5
  • Method Details

    • setMaxRecordLength

      public static void setMaxRecordLength(int length)
      Parameters:
      length - the max record length allowed for XMLSlideShow
    • getMaxRecordLength

      public static int getMaxRecordLength()
      Returns:
      the max record length allowed for XMLSlideShow
    • onDocumentRead

      protected void onDocumentRead() throws IOException
      Description copied from class: POIXMLDocumentPart
      Fired when a package part is read
      Overrides:
      onDocumentRead in class POIXMLDocumentPart
      Throws:
      IOException - a subclass may throw an IOException when a document is read
    • commit

      protected void commit() throws IOException
      Description copied from class: POIXMLDocumentPart
      Save the content in the underlying package part. Default implementation is empty meaning that the package part is left unmodified.

      Sub-classes should override and add logic to marshal the "model" into Ooxml4J.

      For example, the code saving a generic XML entry may look as follows:

       protected void commit() throws IOException {
         PackagePart part = getPackagePart();
         try (OutputStream out = part.getOutputStream()) {
           XmlObject bean = getXmlBean(); //the "model" which holds changes in memory
           bean.save(out, DEFAULT_XML_OPTIONS);
         }
       }
       
      Overrides:
      commit in class POIXMLDocumentPart
      Throws:
      IOException - a subclass may throw an IOException if the changes can't be committed
    • getAllEmbeddedParts

      public List<PackagePart> getAllEmbeddedParts()
      Get the document's embedded files.
      Specified by:
      getAllEmbeddedParts in class POIXMLDocument
      Returns:
      the document's embedded files
    • getPictureData

      public List<XSLFPictureData> getPictureData()
      Description copied from interface: SlideShow
      Returns all Pictures of this slideshow. The returned List is unmodifiable.
      Specified by:
      getPictureData in interface SlideShow<XSLFShape,XSLFTextParagraph>
      Returns:
      a List of PictureData.
    • createSlide

      public XSLFSlide createSlide(XSLFSlideLayout layout)
      Create a slide and initialize it from the specified layout.
      Parameters:
      layout - The layout to use for the new slide.
      Returns:
      created slide
    • createSlide

      public XSLFSlide createSlide()
      Create a blank slide using the default (first) master.
      Specified by:
      createSlide in interface SlideShow<XSLFShape,XSLFTextParagraph>
    • createChart

      public XSLFChart createChart(XSLFSlide slide)
      Create a blank chart on the given slide.
    • createChart

      public XSLFChart createChart()
      This method is used to create template for chart XML.
      Returns:
      Xslf chart object
      Since:
      4.1.0
    • getNotesSlide

      public XSLFNotes getNotesSlide(XSLFSlide slide)
      Return notes slide for the specified slide or create new if it does not exist yet.
    • createNotesMaster

      public void createNotesMaster()
      Create a notes master.
    • getNotesMaster

      public XSLFNotesMaster getNotesMaster()
      Return the Notes Master, if there is one. (May not be present if no notes exist)
    • getSlideMasters

      public List<XSLFSlideMaster> getSlideMasters()
      Description copied from interface: SlideShow
      Returns all slide masters. This doesn't include notes master and other arbitrary masters.
      Specified by:
      getSlideMasters in interface SlideShow<XSLFShape,XSLFTextParagraph>
    • getSlides

      public List<XSLFSlide> getSlides()
      Return all the slides in the slideshow
      Specified by:
      getSlides in interface SlideShow<XSLFShape,XSLFTextParagraph>
    • getCharts

      public List<XSLFChart> getCharts()
      Return all the charts in the slideshow
    • getCommentAuthors

      public XSLFCommentAuthors getCommentAuthors()
      Returns the list of comment authors, if there is one. Will only be present if at least one slide has comments on it.
    • setSlideOrder

      public void setSlideOrder(XSLFSlide slide, int newIndex)
      Parameters:
      newIndex - 0-based index of the slide
    • removeSlide

      public XSLFSlide removeSlide(int index)
      Remove a slide from this presentation.
      Parameters:
      index - The slide number to remove.
      Returns:
      The slide that was removed.
      Throws:
      IllegalStateException - a number of runtime exceptions can be thrown, especially if there are problems with the input format
    • getPageSize

      public Dimension getPageSize()
      Description copied from interface: SlideShow
      Returns the current page size
      Specified by:
      getPageSize in interface SlideShow<XSLFShape,XSLFTextParagraph>
      Returns:
      the page size
    • setPageSize

      public void setPageSize(Dimension pgSize)
      Description copied from interface: SlideShow
      Change the current page size
      Specified by:
      setPageSize in interface SlideShow<XSLFShape,XSLFTextParagraph>
      Parameters:
      pgSize - page size (in points)
    • getCTPresentation

      @Internal public org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation getCTPresentation()
    • addPicture

      public XSLFPictureData addPicture(byte[] pictureData, PictureData.PictureType format)
      Adds a picture to the workbook.
      Specified by:
      addPicture in interface SlideShow<XSLFShape,XSLFTextParagraph>
      Parameters:
      pictureData - The bytes of the picture
      format - The format of the picture.
      Returns:
      the picture data
    • addPicture

      public XSLFPictureData addPicture(InputStream is, PictureData.PictureType format) throws IOException
      Adds a picture to the slideshow.
      Specified by:
      addPicture in interface SlideShow<XSLFShape,XSLFTextParagraph>
      Parameters:
      is - The stream to read image from
      format - The format of the picture
      Returns:
      the picture data
      Throws:
      IOException
      Since:
      3.15 beta 2
    • addPicture

      public XSLFPictureData addPicture(File pict, PictureData.PictureType format) throws IOException
      Adds a picture to the presentation.
      Specified by:
      addPicture in interface SlideShow<XSLFShape,XSLFTextParagraph>
      Parameters:
      pict - The file containing the image to add
      format - The format of the picture.
      Returns:
      the picture data
      Throws:
      IOException
      Since:
      3.15 beta 2
    • findPictureData

      public XSLFPictureData findPictureData(byte[] pictureData)
      check if a picture with this picture data already exists in this presentation
      Specified by:
      findPictureData in interface SlideShow<XSLFShape,XSLFTextParagraph>
      Parameters:
      pictureData - The picture data to find in the SlideShow
      Returns:
      null if picture data is not found in this slideshow
      Since:
      3.15 beta 2
    • findLayout

      public XSLFSlideLayout findLayout(String name)
      Scan the master slides for the first slide layout with the given name.
      Parameters:
      name - The layout name (case-insensitive). Cannot be null.
      Returns:
      the first layout found or null on failure
    • getTableStyles

      public XSLFTableStyles getTableStyles()
    • createMasterSheet

      This method is not yet supported.
      Specified by:
      createMasterSheet in interface SlideShow<XSLFShape,XSLFTextParagraph>
      Throws:
      UnsupportedOperationException - this method is not yet supported
      IOException
    • getMetadataTextExtractor

      public POIXMLPropertiesTextExtractor getMetadataTextExtractor()
      Specified by:
      getMetadataTextExtractor in interface SlideShow<XSLFShape,XSLFTextParagraph>
      Returns:
      an extractor for the slideshow metadata
    • getPersistDocument

      public Object getPersistDocument()
      Specified by:
      getPersistDocument in interface SlideShow<XSLFShape,XSLFTextParagraph>
      Returns:
      the instance which handles the persisting of the slideshow, which is either a subclass of POIDocument or org.apache.poi.ooxml.POIXMLDocument
    • addFont

      public XSLFFontInfo addFont(InputStream fontStream) throws IOException
      Description copied from interface: SlideShow
      Add an EOT font to the slideshow. An EOT or MTX font is a transformed True-Type (.ttf) or Open-Type (.otf) font. To transform a True-Type font use the sfntly library (see "see also" below)

      (Older?) Powerpoint versions handle embedded fonts by converting them to .ttf files and put them into the Windows fonts directory. If the user is not allowed to install fonts, the slideshow can't be opened. While the slideshow is opened, its possible to copy the extracted .ttfs from the fonts directory. When the slideshow is closed, they will be removed.

      Specified by:
      addFont in interface SlideShow<XSLFShape,XSLFTextParagraph>
      Parameters:
      fontStream - the EOT font as stream
      Returns:
      the font info object containing the new font data
      Throws:
      IOException - if the fontData can't be saved or if the fontData is no EOT font
      See Also:
    • getFonts

      public List<XSLFFontInfo> getFonts()
      Specified by:
      getFonts in interface SlideShow<XSLFShape,XSLFTextParagraph>
      Returns:
      a list of registered fonts
    • getFirstSlideNumber

      public int getFirstSlideNumber()
      Returns the number that shall be displayed on the first slide of the presentation. Subsequent slides will be numbered sequentially from this number. The default value is 1 if the property is not set in the presentation file.
      Returns:
      The starting number for the first slide (default is 1).
      Since:
      6.0.0
    • setFirstSlideNumber

      public void setFirstSlideNumber(int num)
      Sets the custom number that shall be displayed on the first slide of the presentation. Subsequent slides will be numbered sequentially from this number. The value is restricted to the range [0, 9999] as defined in the Microsoft Office Implementation Information for ISO/IEC 29500 (MS-OI29500), specifically in Part 1, Section 19.2.1.26, presentation (Presentation), which restricts the XML Schema int datatype.
      Parameters:
      num - The starting number for the first slide (must be between 0 and 9999).
      Throws:
      IllegalArgumentException - if the provided number is outside the allowed range [0, 9999].
      Since:
      6.0.0
    • unsetFirstSlideNumber

      public void unsetFirstSlideNumber()
      Unsets the custom first slide number, reverting the numbering to the default (1). This removes the 'firstSlideNum' attribute from presentation.xml.
      Since:
      6.0.0