Convert PowerPoint to PNG

About PowerPoint to PNG Conversion

The PNG (Portable Network Graphics) format is not as popular as JPEG (Joint Photographic Experts Group), but it still very popular.

Use case: When you have a complex image and size is not an issue, PNG is a better image format than JPEG.

Convert PowerPoint to PNG

Go through these steps:

  1. Instantiate the Presentation class.
  2. Get the slide object from the Presentation.getSlides() collection under the ISlide interface.
  3. Use a ISlide.getImage() method to get the thumbnail for each slide.
  4. Use the  [IImage.save(String formatName, int imageFormat)](https://reference.aspose.com/slides/php-java/aspose.slides/IImage#save(String formatName, int imageFormat)) method to save the slide thumbnail to the PNG format.

This PHP code shows you how to convert a PowerPoint presentation to PNG:

  $pres = new Presentation("pres.pptx");
  try {
    for($index = 0; $index < java_values($pres->getSlides()->size()) ; $index++) {
      $slide = $pres->getSlides()->get_Item($index);
      $slideImage = $slide->getImage();
      try {
        $slideImage->save("image_java_" . $index . ".png", ImageFormat::Png);
      } finally {
        if (!java_is_null($slideImage)) {
          $slideImage->dispose();
        }
      }
    }
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Convert PowerPoint to PNG With Custom Dimensions

If you want to obtain PNG files around a certain scale, you can set the values for desiredX and desiredY, which determine the dimensions of the resulting thumbnail.

This code demonstrates the described operation:

  $pres = new Presentation("pres.pptx");
  try {
    $scaleX = 2.0;
    $scaleY = 2.0;
    for($index = 0; $index < java_values($pres->getSlides()->size()) ; $index++) {
      $slide = $pres->getSlides()->get_Item($index);
      $slideImage = $slide->getImage($scaleX, $scaleY);
      try {
        $slideImage->save("image_java_" . $index . ".png", ImageFormat::Png);
      } finally {
        if (!java_is_null($slideImage)) {
          $slideImage->dispose();
        }
      }
    }
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Convert PowerPoint to PNG With Custom Size

If you want to obtain PNG files around a certain size, you can pass your preferred width and height arguments for ImageSize.

This code shows you how to convert a PowerPoint to PNG while specifying the size for the images:

  $pres = new Presentation("pres.pptx");
  try {
    $size = new Java("java.awt.Dimension", 960, 720);
    for($index = 0; $index < java_values($pres->getSlides()->size()) ; $index++) {
      $slide = $pres->getSlides()->get_Item($index);
      $slideImage = $slide->getImage($size);
      try {
        $slideImage->save("image_java_" . $index . ".png", ImageFormat::Png);
      } finally {
        if (!java_is_null($slideImage)) {
          $slideImage->dispose();
        }
      }
    }
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }