Presentation Viewer

Aspose.Slides for PHP 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:

  1. Create an instance of the Presentation class.
  2. Get the slide reference by its index.
  3. Open a file stream.
  4. Save the slide as an SVG image to the file stream.
$slideIndex = 0;

$presentation = new Presentation("sample.pptx");
$slide = $presentation->getSlides()->get_Item($slideIndex);

$svgStream = new Java("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.

$slideIndex = 0;

$presentation = new Presentation("sample.pptx");
$slide = $presentation->getSlides()->get_Item($slideIndex);

$shapeFormattingController = java_closure(new CustomSvgShapeFormattingController(0), null, java("com.aspose.slides.ISvgShapeFormattingController"));

$svgOptions = new SVGOptions();
$svgOptions->setShapeFormattingController($shapeFormattingController);

$svgStream = new Java("java.io.FileOutputStream", "output.svg");
$slide->writeAsSvg($svgStream, $svgOptions);
$svgStream->close();

$presentation->dispose();
class CustomSvgShapeFormattingController {
    private $m_shapeIndex;

    public function __construct($shapeStartIndex) {
        $this->m_shapeIndex = $shapeStartIndex;
    }

    public function formatShape($svgShape, $shape) {
        $svgShape->setId(sprintf("shape-%d", $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:

  1. Create an instance of the Presentation class.
  2. Get the slide reference by its index.
  3. Get the thumbnail image of the referenced slide at a defined scale.
  4. Save the thumbnail image in any desired image format.
$slideIndex = 0;
$scaleX = 1.0;
$scaleY = $scaleX;

$presentation = new Presentation("sample.pptx");
$slide = $presentation->getSlides()->get_Item($slideIndex);

$image = $slide->getImage($scaleX, $scaleY);
$image->save("output.jpg", 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:

  1. Create an instance of the Presentation class.
  2. Get the slide reference by its index.
  3. Get the thumbnail image of the referenced slide with the defined dimensions.
  4. Save the thumbnail image in any desired image format.
$slideIndex = 0;
$slideSize = new Java("java.awt.Dimension", 1200, 800);

$presentation = new Presentation("sample.pptx");
$slide = $presentation->getSlides()->get_Item($slideIndex);

$image = $slide->getImage($slideSize);
$image->save("output.jpg", 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:

  1. Create an instance of the RenderingOptions class.
  2. Use the RenderingOptions.setSlidesLayoutOptions method to set the position of speaker notes.
  3. Create an instance of the Presentation class.
  4. Get the slide reference by its index.
  5. Get the thumbnail image of the referenced slide with the rendering options.
  6. Save the thumbnail image in any desired image format.
$slideIndex = 0;

$layoutingOptions = new NotesCommentsLayoutingOptions();
$layoutingOptions->setNotesPosition(NotesPositions::BottomTruncated);

$renderingOptions = new RenderingOptions();
$renderingOptions->setSlidesLayoutOptions($layoutingOptions);

$presentation = new Presentation("sample.pptx");
$slide = $presentation->getSlides()->get_Item($slideIndex);

$image = $slide->getImage($renderingOptions);
$image->save("output.png", 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:

Online PowerPoint Viewer