Generating slides preview for presentations
Leave feedback
On this page
Starting from version 24.6, GroupDocs.Editor for Node.js and Java allows generating slide previews from any presentation document in SVG format. This feature enables users to view and inspect the content of a PowerPoint presentation without needing to send it for editing. While the generated slide preview cannot be edited, it can be viewed in any desktop or online image viewer, as well as in modern web browsers that support the SVG format.
This feature works in both trial and licensed modes, with no limitations. Furthermore, generating the slides preview does not consume credits or bytes during its use.
How to Generate a Slide Preview
To generate a slide preview in GroupDocs.Editor for Node.js or Java, you can use the generatePreview(slideIndex) method of the PresentationDocumentInfo class. The slide to preview is specified by its zero-based index (not to be confused with one-based slide numbers). If the index is out of bounds (less than 0 or greater than the number of slides), an IllegalArgumentException will be thrown.
Slide previews can be generated for both encoded and unencoded presentations. For encoded presentations, a valid password must be specified in the getDocumentInfo() method.
The generatePreview(slideIndex) method returns a slide preview as an SVG image, encapsulated in the SvgImage class. This class provides methods to save the SVG content to disk, stream it, and more.
Example Code for Node.js
Here’s an example showing how to load a PowerPoint presentation in Node.js, generate previews for each slide, and save the SVG images to disk:
constgroupdocs=require('groupdocs-editor');constEditor=groupdocs.Editor;constPresentationLoadOptions=groupdocs.options.PresentationLoadOptions;constSvgImage=groupdocs.resources.SvgImage;// Path to the presentation file
constinputPath="Sample.pptx";// Load the presentation into the Editor
consteditor=newEditor(inputPath);// Get document info for this presentation
constdocumentInfo=editor.getDocumentInfo();// Cast the document info to PresentationDocumentInfo
constpresentationInfo=documentInfo.asPresentationDocumentInfo();// Get the number of slides in the presentation
constslideCount=presentationInfo.getPageCount();// Loop through all slides and generate SVG previews
for(leti=0;i<slideCount;i++){// Generate the slide preview as an SVG image
constsvgPreview=presentationInfo.generatePreview(i);// Save the SVG image to a file
svgPreview.save(`output/slide_${i}.svg`);}
Example Code for Java
The following Java example shows how to generate previews for all slides in a PowerPoint presentation and save them as SVG images:
// Obtain a valid full path to the presentation file
StringinputPath="Sample.pptx";// Load the file into the Editor constructor
Editoreditor=newEditor(inputPath);// Get document info for this file
IDocumentInfoinfoUncasted=editor.getDocumentInfo(null);// Cast the 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 for each slide
for(inti=0;i<slidesCount;i++){// Generate one preview as an SVG image
SvgImageoneSvgPreview=infoSlides.generatePreview(i);// Save the preview to a file
oneSvgPreview.save(newFile(outputFolder,oneSvgPreview.getFilenameWithExtension()).getPath());}
Concluding
The slides preview feature is a convenient method for generating non-editable SVG previews of slides from PowerPoint presentations. The generatePreview(slideIndex) method in the PresentationDocumentInfo class allows you to obtain a slide’s preview in vector format, encapsulated in the SvgImage class.
If you prefer a raster format instead of vector, the saveToPng() method in the SvgImage class can be used to convert the SVG content to PNG format and save it to a specified InputStream or file.
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.