Package org.apache.poi.hslf.usermodel
Class HSLFSlideShow
- java.lang.Object
-
- org.apache.poi.POIDocument
-
- org.apache.poi.hslf.usermodel.HSLFSlideShow
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,GenericRecord
,SlideShow<HSLFShape,HSLFTextParagraph>
public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFShape,HSLFTextParagraph>, java.io.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 Summary
Fields Modifier and Type Field Description static java.lang.String
POWERPOINT_DOCUMENT
Powerpoint document entry/stream namestatic java.lang.String
PP95_DOCUMENT
static java.lang.String
PP97_DOCUMENT
-
Constructor Summary
Constructors Constructor Description HSLFSlideShow()
Constructs a new, empty, Powerpoint document.HSLFSlideShow(java.io.InputStream inputStream)
Constructs a Powerpoint document from an input stream.HSLFSlideShow(HSLFSlideShowImpl hslfSlideShow)
Constructs a Powerpoint document from the underlying HSLFSlideShow object.HSLFSlideShow(DirectoryNode root)
Constructs a Powerpoint document from an DirectoryNode.HSLFSlideShow(POIFSFileSystem poifs)
Constructs a Powerpoint document from an POIFSFileSystem.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
addControl(java.lang.String name, java.lang.String progId)
Add a control in this presentationint
addEmbed(POIFSFileSystem poiData)
Add a embedded object to this presentationHSLFFontInfo
addFont(java.io.InputStream fontData)
Add a font in this presentation and also embed its font dataHSLFFontInfo
addFont(FontInfo fontInfo)
Add a font in this presentationint
addMovie(java.lang.String path, int type)
Add a movie in this presentationHSLFPictureData
addPicture(byte[] data, PictureData.PictureType format)
Adds a picture to the presentation.HSLFPictureData
addPicture(java.io.File pict, PictureData.PictureType format)
Adds a picture to the presentation.HSLFPictureData
addPicture(java.io.InputStream is, PictureData.PictureType format)
Adds a picture to the presentation.void
close()
Closes the underlyingPOIFSFileSystem
from which the document was read, if any.void
createInformationProperties()
Will create whichever of SummaryInformation and DocumentSummaryInformation (HPSF) properties are not already part of your document.MasterSheet<HSLFShape,HSLFTextParagraph>
createMasterSheet()
HSLFSlide
createSlide()
Create a blankSlide
.HSLFPictureData
findPictureData(byte[] pictureData)
check if a picture with this picture data already exists in this presentationRecord
getCoreRecordForRefID(int refID)
For a given refID (the internal, 0 based numbering scheme), return the core recordRecord
getCoreRecordForSAS(SlideListWithText.SlideAtomsSet sas)
For a given SlideAtomsSet, return the core record, based on the refID from the SlidePersistAtomDirectoryNode
getDirectory()
Document
getDocumentRecord()
Helper method for usermodel and model: Get the document recordDocumentSummaryInformation
getDocumentSummaryInformation()
Fetch the Document Summary Information of the documentHSLFObjectData[]
getEmbeddedObjects()
Returns the data of all the embedded OLE object in the SlideShowEncryptionInfo
getEncryptionInfo()
HSLFFontInfo
getFont(int idx)
Get a font by indexjava.util.List<HSLFFontInfo>
getFonts()
java.util.List<? extends GenericRecord>
getGenericChildren()
java.util.Map<java.lang.String,java.util.function.Supplier<?>>
getGenericProperties()
static int
getMaxRecordLength()
HPSFPropertiesExtractor
getMetadataTextExtractor()
Record[]
getMostRecentCoreRecords()
Returns an array of the most recent version of all the interesting recordsjava.util.List<HSLFNotes>
getNotes()
Returns an array of all the normal Notes found in the slideshowHeadersFooters
getNotesHeadersFooters()
Return Header / Footer settings for notesint
getNumberOfFonts()
get the number of fonts in the presentationjava.awt.Dimension
getPageSize()
Returns the current page sizejava.lang.Object
getPersistDocument()
java.util.List<HSLFPictureData>
getPictureData()
Returns all Pictures of this slideshow.HeadersFooters
getSlideHeadersFooters()
Return Header / Footer settings for slidesjava.util.List<HSLFSlideMaster>
getSlideMasters()
Returns an array of all the normal Slide Masters found in the slideshowjava.util.List<HSLFSlide>
getSlides()
Returns an array of all the normal Slides found in the slideshowHSLFSlideShowImpl
getSlideShowImpl()
HSLFSoundData[]
getSoundData()
Returns the data of all the embedded sounds in the SlideShowSummaryInformation
getSummaryInformation()
Fetch the Summary Information of the documentjava.util.List<HSLFTitleMaster>
getTitleMasters()
Returns an array of all the normal Title Masters found in the slideshowvoid
readProperties()
Find, and create objects for, the standard Document Information Properties (HPSF).HSLFSlide
removeSlide(int index)
Removes the slide at the given index (0-based).void
reorderSlide(int oldSlideNumber, int newSlideNumber)
Re-orders a slide, to a new position.static void
setMaxRecordLength(int length)
void
setPageSize(java.awt.Dimension pgsize)
Change the current page sizevoid
write()
Writes the document out to the currently openFile
, via the writeablePOIFSFileSystem
it was opened from.void
write(java.io.File newFile)
Writes the document out to the specified newFile
.void
write(java.io.OutputStream out)
Writes the document out to the specified output stream.void
writeProperties(POIFSFileSystem outFS)
Writes out the standard Document Information Properties (HPSF)-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.poi.common.usermodel.GenericRecord
getGenericRecordType
-
-
-
-
Field Detail
-
POWERPOINT_DOCUMENT
public static final java.lang.String POWERPOINT_DOCUMENT
Powerpoint document entry/stream name- See Also:
- Constant Field Values
-
PP97_DOCUMENT
public static final java.lang.String PP97_DOCUMENT
- See Also:
- Constant Field Values
-
PP95_DOCUMENT
public static final java.lang.String PP95_DOCUMENT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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(java.io.InputStream inputStream) throws java.io.IOException
Constructs a Powerpoint document from an input stream.- Throws:
java.io.IOException
- If reading data from the stream failsjava.lang.RuntimeException
- a number of runtime exceptions can be thrown, especially if there are problems with the input format
-
HSLFSlideShow
public HSLFSlideShow(POIFSFileSystem poifs) throws java.io.IOException
Constructs a Powerpoint document from an POIFSFileSystem.- Throws:
java.io.IOException
- If reading data from the file-system failsjava.lang.RuntimeException
- a number of runtime exceptions can be thrown, especially if there are problems with the input format
-
HSLFSlideShow
public HSLFSlideShow(DirectoryNode root) throws java.io.IOException
Constructs a Powerpoint document from an DirectoryNode.- Throws:
java.io.IOException
- If reading data from the DirectoryNode failsjava.lang.RuntimeException
- a number of runtime exceptions can be thrown, especially if there are problems with the input format
-
-
Method Detail
-
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(java.io.OutputStream out) throws java.io.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 aFile
rather than anInputStream
, you must write out usingPOIDocument.write()
or to a different File. Overwriting the currently open file via an OutputStream isn't possible. Ifstream
is aFileOutputStream
on a networked drive or has a high cost/latency associated with each written byte, consider wrapping the OutputStream in aBufferedOutputStream
to improve write performance, or usePOIDocument.write()
/POIDocument.write(File)
if possible.- Specified by:
write
in interfaceSlideShow<HSLFShape,HSLFTextParagraph>
- Specified by:
write
in classPOIDocument
- Parameters:
out
- The stream to write to.- Throws:
java.io.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 java.util.List<HSLFSlide> getSlides()
Returns an array of all the normal Slides found in the slideshow- Specified by:
getSlides
in interfaceSlideShow<HSLFShape,HSLFTextParagraph>
-
getNotes
public java.util.List<HSLFNotes> getNotes()
Returns an array of all the normal Notes found in the slideshow
-
getSlideMasters
public java.util.List<HSLFSlideMaster> getSlideMasters()
Returns an array of all the normal Slide Masters found in the slideshow- Specified by:
getSlideMasters
in interfaceSlideShow<HSLFShape,HSLFTextParagraph>
-
getTitleMasters
public java.util.List<HSLFTitleMaster> getTitleMasters()
Returns an array of all the normal Title Masters found in the slideshow
-
getPictureData
public java.util.List<HSLFPictureData> getPictureData()
Description copied from interface:SlideShow
Returns all Pictures of this slideshow. The returnedList
is unmodifiable.- Specified by:
getPictureData
in interfaceSlideShow<HSLFShape,HSLFTextParagraph>
- Returns:
- a
List
ofPictureData
.
-
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 java.awt.Dimension getPageSize()
Description copied from interface:SlideShow
Returns the current page size- Specified by:
getPageSize
in interfaceSlideShow<HSLFShape,HSLFTextParagraph>
- Returns:
- the page size
-
setPageSize
public void setPageSize(java.awt.Dimension pgsize)
Description copied from interface:SlideShow
Change the current page size- Specified by:
setPageSize
in interfaceSlideShow<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 blankSlide
.- Specified by:
createSlide
in interfaceSlideShow<HSLFShape,HSLFTextParagraph>
- Returns:
- the created
Slide
-
addPicture
public HSLFPictureData addPicture(byte[] data, PictureData.PictureType format) throws java.io.IOException
Description copied from interface:SlideShow
Adds a picture to the presentation.- Specified by:
addPicture
in interfaceSlideShow<HSLFShape,HSLFTextParagraph>
- Parameters:
data
- The bytes of the pictureformat
- The format of the picture.- Returns:
- the picture data reference.
- Throws:
java.io.IOException
-
addPicture
public HSLFPictureData addPicture(java.io.InputStream is, PictureData.PictureType format) throws java.io.IOException
Adds a picture to the presentation.- Specified by:
addPicture
in interfaceSlideShow<HSLFShape,HSLFTextParagraph>
- Parameters:
is
- The stream to read the image fromformat
- The format of the picture.- Returns:
- the picture data.
- Throws:
java.io.IOException
- Since:
- 3.15 beta 2
-
addPicture
public HSLFPictureData addPicture(java.io.File pict, PictureData.PictureType format) throws java.io.IOException
Adds a picture to the presentation.- Specified by:
addPicture
in interfaceSlideShow<HSLFShape,HSLFTextParagraph>
- Parameters:
pict
- the file containing the image to addformat
- The format of the picture.- Returns:
- the picture data.
- Throws:
java.io.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 interfaceSlideShow<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(java.io.InputStream fontData) throws java.io.IOException
Add a font in this presentation and also embed its font data- Specified by:
addFont
in interfaceSlideShow<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:
java.io.IOException
- if the fontData can't be saved or if the fontData is no EOT font- Since:
- POI 4.1.0
- See Also:
- EOT specification, googles sfntly library, Example on how to subset and embed fonts
-
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
ornull
if not found
-
getNumberOfFonts
public int getNumberOfFonts()
get the number of fonts in the presentation- Returns:
- number of fonts
-
getFonts
public java.util.List<HSLFFontInfo> getFonts()
- Specified by:
getFonts
in interfaceSlideShow<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(java.lang.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(java.lang.String name, java.lang.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 a embedded object to this presentation- Returns:
- 0-based index of the embedded object
-
getMetadataTextExtractor
public HPSFPropertiesExtractor getMetadataTextExtractor()
- Specified by:
getMetadataTextExtractor
in interfaceSlideShow<HSLFShape,HSLFTextParagraph>
- Returns:
- an extractor for the slideshow metadata
-
createMasterSheet
public MasterSheet<HSLFShape,HSLFTextParagraph> createMasterSheet()
- Specified by:
createMasterSheet
in interfaceSlideShow<HSLFShape,HSLFTextParagraph>
-
getSlideShowImpl
@Internal public HSLFSlideShowImpl getSlideShowImpl()
- Returns:
- the handler class which holds the hslf records
-
close
public void close() throws java.io.IOException
Description copied from class:POIDocument
Closes the underlyingPOIFSFileSystem
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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classPOIDocument
- Throws:
java.io.IOException
-
getPersistDocument
public java.lang.Object getPersistDocument()
- Specified by:
getPersistDocument
in interfaceSlideShow<HSLFShape,HSLFTextParagraph>
- Returns:
- the instance which handles the persisting of the slideshow,
which is either a subclass of
POIDocument
orPOIXMLDocument
-
getGenericProperties
public java.util.Map<java.lang.String,java.util.function.Supplier<?>> getGenericProperties()
- Specified by:
getGenericProperties
in interfaceGenericRecord
-
getGenericChildren
public java.util.List<? extends GenericRecord> getGenericChildren()
- Specified by:
getGenericChildren
in interfaceGenericRecord
-
write
public void write() throws java.io.IOException
Description copied from class:POIDocument
Writes the document out to the currently openFile
, via the writeablePOIFSFileSystem
it was opened from.This will fail (with an
IllegalStateException
if the document was opened read-only, opened from anInputStream
instead of a File, or if this is not the root document. For those cases, you must usePOIDocument.write(OutputStream)
orPOIDocument.write(File)
to write to a brand new document.- Specified by:
write
in classPOIDocument
- Throws:
java.io.IOException
- thrown on errors writing to the file
-
write
public void write(java.io.File newFile) throws java.io.IOException
Description copied from class:POIDocument
Writes the document out to the specified newFile
. If the file exists, it will be replaced, otherwise a new one will be created- Specified by:
write
in classPOIDocument
- Parameters:
newFile
- The new File to write to.- Throws:
java.io.IOException
- thrown on errors writing to the file
-
getDocumentSummaryInformation
public DocumentSummaryInformation getDocumentSummaryInformation()
Description copied from class:POIDocument
Fetch the Document Summary Information of the document- Overrides:
getDocumentSummaryInformation
in classPOIDocument
- 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 classPOIDocument
- 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 classPOIDocument
-
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 classPOIDocument
-
writeProperties
public void writeProperties(POIFSFileSystem outFS) throws java.io.IOException
Description copied from class:POIDocument
Writes out the standard Document Information Properties (HPSF)- Overrides:
writeProperties
in classPOIDocument
- Parameters:
outFS
- the POIFSFileSystem to write the properties into- Throws:
java.io.IOException
- if an error when writing to thePOIFSFileSystem
occurs
-
getDirectory
public DirectoryNode getDirectory()
- Overrides:
getDirectory
in classPOIDocument
-
getEncryptionInfo
public EncryptionInfo getEncryptionInfo()
- Overrides:
getEncryptionInfo
in classPOIDocument
- Returns:
- the encryption info if the document is encrypted, otherwise
null
-
-