Class HSLFSlideShow

java.lang.Object
org.apache.poi.POIDocument
org.apache.poi.hslf.usermodel.HSLFSlideShow
All Implemented Interfaces:
Closeable, AutoCloseable, GenericRecord, SlideShow<HSLFShape,HSLFTextParagraph>

public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFShape,HSLFTextParagraph>, Closeable, GenericRecord
This class is a friendly wrapper on top of the more scary HSLFSlideShow. TODO: - figure out how to match notes to their correct sheet (will involve understanding DocSlideList and DocNotesList) - handle Slide creation cleaner
  • Field Details

  • Constructor Details

    • HSLFSlideShow

      public HSLFSlideShow(HSLFSlideShowImpl hslfSlideShow)
      Constructs a Powerpoint document from the underlying HSLFSlideShow object. Finds the model stuff from this
      Parameters:
      hslfSlideShow - the HSLFSlideShow to base on
    • HSLFSlideShow

      public HSLFSlideShow()
      Constructs a new, empty, Powerpoint document.
    • HSLFSlideShow

      public HSLFSlideShow(InputStream inputStream) throws IOException
      Constructs a Powerpoint document from an input stream.
      Throws:
      IOException - If reading data from the stream fails
      IllegalStateException - a number of runtime exceptions can be thrown, especially if there are problems with the input format
    • HSLFSlideShow

      public HSLFSlideShow(InputStream inputStream, char[] password) throws IOException
      Constructs a Powerpoint document from an input stream.
      Parameters:
      inputStream - stream containing ppt data
      password - in char array format (can be null)
      Throws:
      IOException - If reading data from the stream fails
      IllegalStateException - a number of runtime exceptions can be thrown, especially if there are problems with the input format
      Since:
      6.0.0
    • HSLFSlideShow

      public HSLFSlideShow(POIFSFileSystem poifs) throws IOException
      Constructs a Powerpoint document from an POIFSFileSystem.
      Throws:
      IOException - If reading data from the file-system fails
      IllegalStateException - a number of runtime exceptions can be thrown, especially if there are problems with the input format
    • HSLFSlideShow

      public HSLFSlideShow(POIFSFileSystem poifs, char[] password) throws IOException
      Constructs a Powerpoint document from an POIFSFileSystem.
      Parameters:
      poifs - POIFSFileSystem containing ppt data
      password - in char array format (can be null)
      Throws:
      IOException - If reading data from the file-system fails
      IllegalStateException - a number of runtime exceptions can be thrown, especially if there are problems with the input format
      Since:
      6.0.0
    • HSLFSlideShow

      public HSLFSlideShow(DirectoryNode root) throws IOException
      Constructs a Powerpoint document from an DirectoryNode.
      Throws:
      IOException - If reading data from the DirectoryNode fails
      IllegalStateException - a number of runtime exceptions can be thrown, especially if there are problems with the input format
    • HSLFSlideShow

      public HSLFSlideShow(DirectoryNode root, char[] password) throws IOException
      Constructs a Powerpoint document from an DirectoryNode.
      Parameters:
      root - DirectoryNode containing ppt data
      password - in char array format (can be null)
      Throws:
      IOException - If reading data from the DirectoryNode fails
      IllegalStateException - a number of runtime exceptions can be thrown, especially if there are problems with the input format
      Since:
      6.0.0
  • Method Details

    • setMaxRecordLength

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

      public static int getMaxRecordLength()
      Returns:
      the max record length allowed for HSLFSlideShow
    • getCoreRecordForSAS

      public Record getCoreRecordForSAS(SlideListWithText.SlideAtomsSet sas)
      For a given SlideAtomsSet, return the core record, based on the refID from the SlidePersistAtom
    • getCoreRecordForRefID

      public Record getCoreRecordForRefID(int refID)
      For a given refID (the internal, 0 based numbering scheme), return the core record
      Parameters:
      refID - the refID
    • write

      public void write(OutputStream out) throws IOException
      Description copied from class: POIDocument
      Writes the document out to the specified output stream. The stream is not closed as part of this operation. Note - if the Document was opened from a File rather than an InputStream, you must write out using POIDocument.write() or to a different File. Overwriting the currently open file via an OutputStream isn't possible. If stream is a FileOutputStream on a networked drive or has a high cost/latency associated with each written byte, consider wrapping the OutputStream in a BufferedOutputStream to improve write performance, or use POIDocument.write() / POIDocument.write(File) if possible.
      Specified by:
      write in interface SlideShow<HSLFShape,HSLFTextParagraph>
      Specified by:
      write in class POIDocument
      Parameters:
      out - The stream to write to.
      Throws:
      IOException - thrown on errors writing to the stream
    • getMostRecentCoreRecords

      public Record[] getMostRecentCoreRecords()
      Returns an array of the most recent version of all the interesting records
    • getSlides

      public List<HSLFSlide> getSlides()
      Returns an array of all the normal Slides found in the slideshow
      Specified by:
      getSlides in interface SlideShow<HSLFShape,HSLFTextParagraph>
    • getNotes

      public List<HSLFNotes> getNotes()
      Returns an array of all the normal Notes found in the slideshow
    • getSlideMasters

      public List<HSLFSlideMaster> getSlideMasters()
      Returns an array of all the normal Slide Masters found in the slideshow
      Specified by:
      getSlideMasters in interface SlideShow<HSLFShape,HSLFTextParagraph>
    • getTitleMasters

      public List<HSLFTitleMaster> getTitleMasters()
      Returns an array of all the normal Title Masters found in the slideshow
    • getPictureData

      public List<HSLFPictureData> getPictureData()
      Description copied from interface: SlideShow
      Returns all Pictures of this slideshow. The returned List is unmodifiable.
      Specified by:
      getPictureData in interface SlideShow<HSLFShape,HSLFTextParagraph>
      Returns:
      a List of PictureData.
    • getEmbeddedObjects

      public HSLFObjectData[] getEmbeddedObjects()
      Returns the data of all the embedded OLE object in the SlideShow
    • getSoundData

      public HSLFSoundData[] getSoundData()
      Returns the data of all the embedded sounds in the SlideShow
    • getPageSize

      public Dimension getPageSize()
      Description copied from interface: SlideShow
      Returns the current page size
      Specified by:
      getPageSize in interface SlideShow<HSLFShape,HSLFTextParagraph>
      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<HSLFShape,HSLFTextParagraph>
      Parameters:
      pgsize - page size (in points)
    • getDocumentRecord

      public Document getDocumentRecord()
      Helper method for usermodel and model: Get the document record
    • reorderSlide

      public void reorderSlide(int oldSlideNumber, int newSlideNumber)
      Re-orders a slide, to a new position.
      Parameters:
      oldSlideNumber - The old slide number (1 based)
      newSlideNumber - The new slide number (1 based)
    • removeSlide

      public HSLFSlide removeSlide(int index)
      Removes the slide at the given index (0-based).

      Shifts any subsequent slides to the left (subtracts one from their slide numbers).

      Parameters:
      index - the index of the slide to remove (0-based)
      Returns:
      the slide that was removed from the slide show.
    • createSlide

      public HSLFSlide createSlide()
      Create a blank Slide.
      Specified by:
      createSlide in interface SlideShow<HSLFShape,HSLFTextParagraph>
      Returns:
      the created Slide
    • addPicture

      public HSLFPictureData addPicture(byte[] data, PictureData.PictureType format) throws IOException
      Description copied from interface: SlideShow
      Adds a picture to the presentation.
      Specified by:
      addPicture in interface SlideShow<HSLFShape,HSLFTextParagraph>
      Parameters:
      data - The bytes of the picture
      format - The format of the picture.
      Returns:
      the picture data reference.
      Throws:
      IOException
    • addPicture

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

      public HSLFPictureData addPicture(File pict, PictureData.PictureType format) throws IOException
      Adds a picture to the presentation.
      Specified by:
      addPicture in interface SlideShow<HSLFShape,HSLFTextParagraph>
      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 HSLFPictureData findPictureData(byte[] pictureData)
      check if a picture with this picture data already exists in this presentation
      Specified by:
      findPictureData in interface SlideShow<HSLFShape,HSLFTextParagraph>
      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 3
    • addFont

      public HSLFFontInfo addFont(FontInfo fontInfo)
      Add a font in this presentation
      Parameters:
      fontInfo - the font to add
      Returns:
      the registered HSLFFontInfo - the font info object is unique based on the typeface
    • addFont

      public HSLFFontInfo addFont(InputStream fontData) throws IOException
      Add a font in this presentation and also embed its font data
      Specified by:
      addFont in interface SlideShow<HSLFShape,HSLFTextParagraph>
      Parameters:
      fontData - the EOT font data as stream
      Returns:
      the registered HSLFFontInfo - the font info object is unique based on the typeface
      Throws:
      IOException - if the fontData can't be saved or if the fontData is no EOT font
      Since:
      4.1.0
      See Also:
    • getFont

      public HSLFFontInfo getFont(int idx)
      Get a font by index
      Parameters:
      idx - 0-based index of the font
      Returns:
      of an instance of PPFont or null if not found
    • getNumberOfFonts

      public int getNumberOfFonts()
      get the number of fonts in the presentation
      Returns:
      number of fonts
    • getFonts

      public List<HSLFFontInfo> getFonts()
      Specified by:
      getFonts in interface SlideShow<HSLFShape,HSLFTextParagraph>
      Returns:
      a list of registered fonts
    • getSlideHeadersFooters

      public HeadersFooters getSlideHeadersFooters()
      Return Header / Footer settings for slides
      Returns:
      Header / Footer settings for slides
    • getNotesHeadersFooters

      public HeadersFooters getNotesHeadersFooters()
      Return Header / Footer settings for notes
      Returns:
      Header / Footer settings for notes
    • addMovie

      public int addMovie(String path, int type)
      Add a movie in this presentation
      Parameters:
      path - the path or url to the movie
      Returns:
      0-based index of the movie
    • addControl

      public int addControl(String name, String progId)
      Add a control in this presentation
      Parameters:
      name - name of the control, e.g. "Shockwave Flash Object"
      progId - OLE Programmatic Identifier, e.g. "ShockwaveFlash.ShockwaveFlash.9"
      Returns:
      0-based index of the control
    • addEmbed

      public int addEmbed(POIFSFileSystem poiData)
      Add an embedded object to this presentation
      Returns:
      0-based index of the embedded object
    • getMetadataTextExtractor

      public HPSFPropertiesExtractor getMetadataTextExtractor()
      Specified by:
      getMetadataTextExtractor in interface SlideShow<HSLFShape,HSLFTextParagraph>
      Returns:
      an extractor for the slideshow metadata
    • createMasterSheet

      public MasterSheet<HSLFShape,HSLFTextParagraph> createMasterSheet()
      Specified by:
      createMasterSheet in interface SlideShow<HSLFShape,HSLFTextParagraph>
    • getSlideShowImpl

      @Internal public HSLFSlideShowImpl getSlideShowImpl()
      Returns:
      the handler class which holds the hslf records
    • close

      public void close() throws IOException
      Description copied from class: POIDocument
      Closes the underlying POIFSFileSystem from which the document was read, if any. Has no effect on documents opened from an InputStream, or newly created ones.

      Once close() has been called, no further operations should be called on the document.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class POIDocument
      Throws:
      IOException
    • getPersistDocument

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

      public Map<String,Supplier<?>> getGenericProperties()
      Specified by:
      getGenericProperties in interface GenericRecord
    • getGenericChildren

      public List<? extends GenericRecord> getGenericChildren()
      Specified by:
      getGenericChildren in interface GenericRecord
    • write

      public void write() throws IOException
      Description copied from class: POIDocument
      Writes the document out to the currently open File, via the writeable POIFSFileSystem it was opened from.

      This will fail (with an IllegalStateException if the document was opened read-only, opened from an InputStream instead of a File, or if this is not the root document. For those cases, you must use POIDocument.write(OutputStream) or POIDocument.write(File) to write to a brand new document.

      Specified by:
      write in class POIDocument
      Throws:
      IOException - thrown on errors writing to the file
    • write

      public void write(File newFile) throws IOException
      Description copied from class: POIDocument
      Writes the document out to the specified new File. If the file exists, it will be replaced, otherwise a new one will be created
      Specified by:
      write in class POIDocument
      Parameters:
      newFile - The new File to write to.
      Throws:
      IOException - thrown on errors writing to the file
    • setOutputPassword

      public void setOutputPassword(char[] password)
      Set the password to be used to password protect the slideshow when writing out. If null is passed any password previously set via this method is cleared; in that case the thread-level password from Biff8EncryptionKey.getCurrentUserPassword() is used (if set), otherwise the output will be unencrypted.

      The password supplied to the constructor for reading an encrypted file is not automatically used as the output password.

      Parameters:
      password - as a char array, or null to clear
      Since:
      6.0.0
    • getDocumentSummaryInformation

      public DocumentSummaryInformation getDocumentSummaryInformation()
      Description copied from class: POIDocument
      Fetch the Document Summary Information of the document
      Overrides:
      getDocumentSummaryInformation in class POIDocument
      Returns:
      The Document Summary Information or null if it could not be read for this document.
    • getSummaryInformation

      public SummaryInformation getSummaryInformation()
      Description copied from class: POIDocument
      Fetch the Summary Information of the document
      Overrides:
      getSummaryInformation in class POIDocument
      Returns:
      The Summary information for the document or null if it could not be read for this document.
    • createInformationProperties

      public void createInformationProperties()
      Description copied from class: POIDocument
      Will create whichever of SummaryInformation and DocumentSummaryInformation (HPSF) properties are not already part of your document. This is normally useful when creating a new document from scratch. If the information properties are already there, then nothing will happen.
      Overrides:
      createInformationProperties in class POIDocument
    • readProperties

      public void readProperties()
      Description copied from class: POIDocument
      Find, and create objects for, the standard Document Information Properties (HPSF). If a given property set is missing or corrupt, it will remain null;
      Overrides:
      readProperties in class POIDocument
    • getPropertySet

      protected PropertySet getPropertySet(String setName) throws IOException
      Description copied from class: POIDocument
      For a given named property entry, either return it or null if if it wasn't found
      Overrides:
      getPropertySet in class POIDocument
      Parameters:
      setName - The property to read
      Returns:
      The value of the given property or null if it wasn't found.
      Throws:
      IOException - If retrieving properties fails
    • getPropertySet

      protected PropertySet getPropertySet(String setName, EncryptionInfo encryptionInfo) throws IOException
      Description copied from class: POIDocument
      For a given named property entry, either return it or null if if it wasn't found
      Overrides:
      getPropertySet in class POIDocument
      Parameters:
      setName - The property to read
      encryptionInfo - the encryption descriptor in case of cryptoAPI encryption
      Returns:
      The value of the given property or null if it wasn't found.
      Throws:
      IOException - If retrieving properties fails
    • writeProperties

      protected void writeProperties() throws IOException
      Description copied from class: POIDocument
      Writes out the updated standard Document Information Properties (HPSF) into the currently open POIFSFileSystem
      Overrides:
      writeProperties in class POIDocument
      Throws:
      IOException - if an error when writing to the open POIFSFileSystem occurs
    • writeProperties

      public void writeProperties(POIFSFileSystem outFS) throws IOException
      Description copied from class: POIDocument
      Writes out the standard Document Information Properties (HPSF)
      Overrides:
      writeProperties in class POIDocument
      Parameters:
      outFS - the POIFSFileSystem to write the properties into
      Throws:
      IOException - if an error when writing to the POIFSFileSystem occurs
    • writeProperties

      protected void writeProperties(POIFSFileSystem outFS, List<String> writtenEntries) throws IOException
      Description copied from class: POIDocument
      Writes out the standard Document Information Properties (HPSF)
      Overrides:
      writeProperties in class POIDocument
      Parameters:
      outFS - the POIFSFileSystem to write the properties into
      writtenEntries - a list of POIFS entries to add the property names too
      Throws:
      IOException - if an error when writing to the POIFSFileSystem occurs
    • validateInPlaceWritePossible

      protected void validateInPlaceWritePossible() throws IllegalStateException
      Description copied from class: POIDocument
      Called during a POIDocument.write() to ensure that the Document (and associated POIFSFileSystem) was opened in a way compatible with an in-place write.
      Overrides:
      validateInPlaceWritePossible in class POIDocument
      Throws:
      IllegalStateException - if the document was opened suitably
    • getDirectory

      public DirectoryNode getDirectory()
      Overrides:
      getDirectory in class POIDocument
    • clearDirectory

      protected void clearDirectory()
      Description copied from class: POIDocument
      Clear/unlink the attached directory entry
      Overrides:
      clearDirectory in class POIDocument
    • initDirectory

      protected boolean initDirectory()
      Description copied from class: POIDocument
      check if we were created by POIFS otherwise create a new dummy POIFS for storing the package data
      Overrides:
      initDirectory in class POIDocument
      Returns:
      true if dummy directory was created, false otherwise
    • replaceDirectory

      protected void replaceDirectory(DirectoryNode newDirectory) throws IOException
      Description copied from class: POIDocument
      Replaces the attached directory, e.g. if this document is written to a new POIFSFileSystem
      Overrides:
      replaceDirectory in class POIDocument
      Parameters:
      newDirectory - the new directory
      Throws:
      IOException - if accessing the file-system fails.
    • getEncryptedPropertyStreamName

      protected String getEncryptedPropertyStreamName()
      Overrides:
      getEncryptedPropertyStreamName in class POIDocument
      Returns:
      the stream name of the property set collection, if the document is encrypted
    • getEncryptionInfo

      public EncryptionInfo getEncryptionInfo()
      Overrides:
      getEncryptionInfo in class POIDocument
      Returns:
      the encryption info if the document is encrypted, otherwise null