Presentation Viewer

Live Example

You can try Aspose.Slides Viewer free app to see what you can implement with Aspose.Slides API:

todo:image_alt_text

Generate SVG Image from Slide

To generate an SVG image from any desired slide with Aspose.Slides for PHP via Java, please follow the steps below:

  • Create an instance of the Presentation class.
  • Obtain the desired slide’s reference by using its ID or index.
  • Get the SVG image in a memory stream.
  • Save the memory stream to file.
  # Instantiate a Presentation class that represents the presentation file
  $pres = new Presentation("CreateSlidesSVGImage.pptx");
  try {
    # Access the first slide
    $sld = $pres->getSlides()->get_Item(0);
    # Create a memory stream object
    $svgStream = new Java("java.io.FileOutputStream", "Aspose_out.svg");
    # Generate SVG image of slide and save in memory stream
    $sld->writeAsSvg($svgStream);
    $svgStream->close();
  } catch (JavaException $e) {
  } finally {
    $pres->dispose();
  }

Generate SVG with Custom Shape IDS

Aspose.Slides for PHP via Java can be used to generate SVG from slide with custom shape ID. For that, use ID property from ISvgShape, which represents custom ID of shapes in generated SVG. CustomSvgShapeFormattingController can be used to set shape ID.


  class CustomSvgShapeFormattingController {
    private $m_shapeIndex;

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

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

    function formatShape($svgShape, $shape) {
      $svgShape->setId(sprintf("shape-%d", $m_shapeIndex++));
    }
  }

  $pres = new Presentation("pptxFileName.pptx");
  try {
    $stream = new Java("java.io.FileOutputStream", "Aspose_out.svg");
    try {
      $svgOptions = new SVGOptions();
      $shapeFormattingController = java_closure(new CustomSvgShapeFormattingController(), null, java("com.aspose.slides.ISvgShapeFormattingController"));
      $svgOptions->setShapeFormattingController($shapeFormattingController);
      $pres->getSlides()->get_Item(0)->writeAsSvg($stream, $svgOptions);
    } finally {
      if (!java_is_null($stream)) {
        $stream->close();
      }
    }
  } catch (JavaException $e) {
  } finally {
    $pres->dispose();
  }

Create Slides Thumbnail Image

Aspose.Slides for PHP via Java help you generate thumbnail images of the slides. To generate the thumbnail of any desired slide using Aspose.Slides for PHP via Java:

  1. Create an instance of the Presentation class.
  2. Obtain the reference of any desired slide by using its ID or index.
  3. Get the thumbnail image of the referenced slide on a specified scale.
  4. Save the thumbnail image in any desired image format.
  # Instantiate a Presentation class that represents the presentation file
  $pres = new Presentation("ThumbnailFromSlide.pptx");
  try {
    # Access the first slide
    $sld = $pres->getSlides()->get_Item(0);
    # Create a full scale image
    $slideImage = $sld->getImage(1.0, 1.0);
    # Save the image to disk in JPEG format
    try {
      $slideImage->save("Thumbnail_out.jpg", ImageFormat::Jpeg);
    } finally {
      if (!java_is_null($slideImage)) {
        $slideImage->dispose();
      }
    }
  } finally {
    $pres->dispose();
  }

Create Thumbnail with User Defined Dimensions

  1. Create an instance of the Presentation class.
  2. Obtain the reference of any desired slide by using its ID or index.
  3. Get the thumbnail image of the referenced slide on a specified scale.
  4. Save the thumbnail image in any desired image format.
  # Instantiate a Presentation class that represents the presentation file
  $pres = new Presentation("ThumbnailWithUserDefinedDimensions.pptx");
  try {
    # Access the first slide
    $sld = $pres->getSlides()->get_Item(0);
    # User defined dimension
    $desiredX = 1200;
    $desiredY = 800;
    # Getting scaled value  of X and Y
    $ScaleX = 1.0 / $pres->getSlideSize()->getSize()->getWidth() * $desiredX;
    $ScaleY = 1.0 / $pres->getSlideSize()->getSize()->getHeight() * $desiredY;
    # Create a full scale image
    $slideImage = $sld->getImage($ScaleX, $ScaleY);
    # Save the image to disk in JPEG format
    try {
      $slideImage->save("Thumbnail_out.jpg", ImageFormat::Jpeg);
    } finally {
      if (!java_is_null($slideImage)) {
        $slideImage->dispose();
      }
    }
  } finally {
    $pres->dispose();
  }

Create Thumbnail from Slide in Notes Slides View

To generate the thumbnail of any desired slide in Notes Slide View using Aspose.Slides for PHP via Java:

  1. Create an instance of the Presentation class.
  2. Obtain the reference of any desired slide by using its ID or index.
  3. Get the thumbnail image of the referenced slide on a specified scale in Notes Slide view.
  4. Save the thumbnail image in any desired image format.

The code snippet below produces a thumbnail of the first slide of a presentation in Notes Slide View.

  # Instantiate a Presentation class that represents the presentation file
  $pres = new Presentation("ThumbnailWithUserDefinedDimensions.pptx");
  try {
    # Access the first slide
    $sld = $pres->getSlides()->get_Item(0);
    # User defined dimension
    $desiredX = 1200;
    $desiredY = 800;
    # Getting scaled value  of X and Y
    $ScaleX = 1.0 / $pres->getSlideSize()->getSize()->getWidth() * $desiredX;
    $ScaleY = 1.0 / $pres->getSlideSize()->getSize()->getHeight() * $desiredY;
    $opts = new RenderingOptions();
    $opts->getNotesCommentsLayouting()->setNotesPosition(NotesPositions::BottomTruncated);
    # Create a full scale image
    $slideImage = $sld->getImage($opts, $ScaleX, $ScaleY);
    # Save the image to disk in JPEG format
    try {
      $slideImage->save("Thumbnail_out.jpg", ImageFormat::Jpeg);
    } finally {
      if (!java_is_null($slideImage)) {
        $slideImage->dispose();
      }
    }
  } finally {
    $pres->dispose();
  }