Presentation Viewer
Aspose.Slides for Node.js via Java is used to create presentation files with slides. These slides can be viewed by opening presentations in Microsoft PowerPoint, for example. However, sometimes developers may need to view slides as images in their preferred image viewer or create their own presentation viewer. In such cases, Aspose.Slides allows you to export an individual slide as an image. This article describes how to do it.
Generate an SVG Image from a Slide
To generate an SVG image from a presentation slide with Aspose.Slides, please follow the steps below:
- Create an instance of the Presentation class.
- Get the slide reference by its index.
- Open a file stream.
- Save the slide as an SVG image to the file stream.
var slideIndex = 0;
var presentation = new aspose.slides.Presentation("sample.pptx");
var slide = presentation.getSlides().get_Item(slideIndex);
var svgStream = java.newInstanceSync("java.io.FileOutputStream", "output.svg");
slide.writeAsSvg(svgStream);
svgStream.close();
presentation.dispose();
Generate an SVG with a Custom Shape ID
Aspose.Slides can be used to generate an SVG from a slide with a custom shape ID. To do this, use the setId
method from SvgShape. CustomSvgShapeFormattingController
can be used to set the shape ID.
var slideIndex = 0;
var presentation = new aspose.slides.Presentation("sample.pptx");
var slide = presentation.getSlides().get_Item(slideIndex);
var svgOptions = new aspose.slides.SVGOptions();
svgOptions.setShapeFormattingController(new CustomSvgShapeFormattingController(0));
var svgStream = java.newInstanceSync("java.io.FileOutputStream", "output.svg");
slide.writeAsSvg(svgStream, svgOptions);
svgStream.close();
presentation.dispose();
class CustomSvgShapeFormattingController {
constructor(shapeStartIndex = 0) {
this.m_shapeIndex = shapeStartIndex;
}
formatShape(svgShape, shape) {
svgShape.setId(`shape-${this.m_shapeIndex++}`);
}
}
Create a Slide Thumbnail Image
Aspose.Slides helps you generate thumbnail images of slides. To generate a thumbnail of a slide using Aspose.Slides, please follow the steps below:
- Create an instance of the Presentation class.
- Get the slide reference by its index.
- Get the thumbnail image of the referenced slide at a defined scale.
- Save the thumbnail image in any desired image format.
const slideIndex = 0;
const scaleX = 1;
const scaleY = scaleX;
var presentation = new aspose.slides.Presentation("sample.pptx");
var slide = presentation.getSlides().get_Item(slideIndex);
var image = slide.getImage(scaleX, scaleY);
image.save("output.jpg", aspose.slides.ImageFormat.Jpeg);
image.dispose();
presentation.dispose();
Create a Slide Thumbnail with User Defined Dimensions
To create a slide thumbnail image with user defined dimensions, please follow the steps below:
- Create an instance of the Presentation class.
- Get the slide reference by its index.
- Get the thumbnail image of the referenced slide with the defined dimensions.
- Save the thumbnail image in any desired image format.
var slideIndex = 0;
var slideSize = java.newInstanceSync("java.awt.Dimension", 1200, 800);
var presentation = new aspose.slides.Presentation("sample.pptx");
var slide = presentation.getSlides().get_Item(slideIndex);
var image = slide.getImage(slideSize);
image.save("output.jpg", aspose.slides.ImageFormat.Jpeg);
image.dispose();
presentation.dispose();
Create a Slide Thumbnail with Speaker Notes
To generate the thumbnail of a slide with speaker notes using Aspose.Slides, please follow the steps below:
- Create an instance of the RenderingOptions class.
- Use the
RenderingOptions.setSlidesLayoutOptions
method to set the position of speaker notes. - Create an instance of the Presentation class.
- Get the slide reference by its index.
- Get the thumbnail image of the referenced slide with the rendering options.
- Save the thumbnail image in any desired image format.
var slideIndex = 0;
var layoutingOptions = new aspose.slides.NotesCommentsLayoutingOptions();
layoutingOptions.setNotesPosition(aspose.slides.NotesPositions.BottomTruncated);
var renderingOptions = new aspose.slides.RenderingOptions();
renderingOptions.setSlidesLayoutOptions(layoutingOptions);
var presentation = new aspose.slides.Presentation("sample.pptx");
var slide = presentation.getSlides().get_Item(slideIndex);
var image = slide.getImage(renderingOptions);
image.save("output.png", aspose.slides.ImageFormat.Png);
image.dispose();
presentation.dispose();
Live Example
You can try Aspose.Slides Viewer free app to see what you can implement with Aspose.Slides API: