Generating slides preview for presentation
Leave feedback
On this page
Starting from version 23.2, the GroupDocs.Editor for Java allows generating the preview for any slide in the presentation document in SVG format. This feature allows the end-user to view and inspect the content of the presentation without actually sending it for edit. This generated slide preview cannot be edited, but it can be viewed in any desktop or online image viewer as well in the browser (because any modern browser actually supports SVG format).
This feature allows end-users to generate a preview for any slide within the presentation regardless of the licensing mode of the GroupDcos.Editor for Java: it works the same for both trial and licensed mode, there are no trial limitations for this feature. While generating the slides preview, the GroupDocs.Editor doesn’t write off the consumed bytes or credits.
For generating the slides preview the new instance method generatePreview(int slideIndex) from the struct com.groupdocs.editor.metadata.PresentationDocumentInfo should be used, and slide is specified by its zero-based index (do not confuse with the slide numbers, which are 1-based). If the specified index is lesser than 0 or exceeds the number of slides within a given presentation, then the IllegalArgumentException exception will be thrown. Slide previews can be generated for both encoded and unencoded presentations; for encoded the end-user must specify a valid password in the getDocumentInfo method.
The code sample below shows opening an unprotected presentation file and generating the previews for every slide. Then these previews are saved to the disk.
// Obtain a valid full path to the presentation file
StringinputPath="Sample.pptx";// Load file to the Editor constructor
Editoreditor=newEditor(inputPath);{// Get document info for this file
IDocumentInfoinfoUncasted=editor.getDocumentInfo(null);// Cast this document info to the PresentationDocumentInfo type
PresentationDocumentInfoinfoSlides=(PresentationDocumentInfo)infoUncasted;// Get the number of all slides
intslidesCount=infoSlides.getPageCount();//Iterate through all slides and generate the preview on every iteration
for(inti=0;i<slidesCount;i++){// Generate one preview as SVG image by slide index
SvgImageoneSvgPreview=infoSlides.generatePreview(i);// Save it to the file
oneSvgPreview.save(newFile(outputFolder,oneSvgPreview.getFilenameWithExtension()).getPath());}}
Concluding, the new slides preview feature is by its essence a new public method in the existing com.groupdocs.editor.metadata.PresentationDocumentInfo struct, that obtains a slide index and returns an instance of SvgImage class. If the end-user needs to obtain a preview of the slide in a raster format, but not in the vector, he can use the saveToPng method in the SvgImage class — this method converts the SVG content of the current SvgImage to the PNG format and saves it to the specified InputStream.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.