Generating slides preview for presentation

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 generatePreview(int slideIndex) method returns a slide preview as an SVG vector image, that is encapsulated in the SvgImage public class from the com.groupdocs.editor.htmlcss.resources.images.vector namespace. This class has all necessary methods and properties to obtain the content of an SVG image in any desired form, save it to disk and so on.

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
String inputPath = "Sample.pptx";

// Load file to the Editor constructor
Editor editor = new Editor(inputPath);
	// Get document info for this file
	IDocumentInfo infoUncasted = editor.getDocumentInfo(null);

	// Cast this document info to the PresentationDocumentInfo type
	PresentationDocumentInfo infoSlides = (PresentationDocumentInfo)infoUncasted;

	// Get the number of all slides
	int slidesCount = infoSlides.getPageCount();

	//Iterate through all slides and generate the preview on every iteration
	for (int i = 0; i < slidesCount; i++)
		// Generate one preview as SVG image by slide index
		SvgImage oneSvgPreview = infoSlides.generatePreview(i);

		// Save it to the file File(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.

On this page