Convert Powerpoint to JPG

About PowerPoint to JPG Conversion

With Aspose.Slides API you can convert PowerPoint PPT or PPTX presentation to JPG image. It is also possible to convert PPT/PPTX to JPEG, PNG or SVG. With this features it’s easy to implement your own presentation viewer, create  the thumbnail for every slide. This may be useful if you want to protect presentation slides from copywriting, demonstrate presentation in read-only mode. Aspose.Slides allows to convert the whole presentation or a certain slide into image formats. 

[todo:image_alt_text

Convert PowerPoint PPT/PPTX to JPG

Here are the steps to convert PPT/PPTX to JPG:

  1. Create an instance of Presentation type.
  2. Get the slide object of ISlide type from Presentation.getSlides() collection.
  3. Create the thumbnail of each slide and then convert it into JPG. ISlide.getImage(float scaleX, float scaleY) method is used to get a thumbnail of a slide, it returns Images object as a result. getImage method has to be called from the needed slide of ISlide type, the scales of the resulting thumbnail are passed into the method.
  4. After you get the slide thumbnail, call [IImage.save(String formatName, int imageFormat)](https://reference.aspose.com/slides/php-java/aspose.slides/IImage#save(String formatName, int imageFormat)) method from the thumbnail object. Pass the resulting file name and the image format into it. 
  $pres = new Presentation("PowerPoint-Presentation.pptx");
  try {
    foreach($pres->getSlides() as $sld) {
      # Creates a full scale image
      $slideImage = $sld->getImage(1.0, 1.0);
      # Saves the image to disk in JPEG format
      try {
        $slideImage->save(String->format("Slide_%d.jpg", $sld->getSlideNumber()), ImageFormat::Jpeg);
      } finally {
        if (!java_is_null($slideImage)) {
          $slideImage->dispose();
        }
      }
    }
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Convert PowerPoint PPT/PPTX to JPG with Customized Dimensions

To change the dimension of the resulting thumbnail and JPG image, you can set the ScaleX and ScaleY values by passing them into the ISlide.getImage(float scaleX, float scaleY) methods:

  $pres = new Presentation("PowerPoint-Presentation.pptx");
  try {
    # Defines dimensions
    $desiredX = 1200;
    $desiredY = 800;
    # Gets scaled values of X and Y
    $ScaleX = 1.0 / $pres->getSlideSize()->getSize()->getWidth() * $desiredX;
    $ScaleY = 1.0 / $pres->getSlideSize()->getSize()->getHeight() * $desiredY;
    foreach($pres->getSlides() as $sld) {
      # Creates a full scale image
      $slideImage = $sld->getImage($ScaleX, $ScaleY);
      # Saves the image to disk in JPEG format
      try {
        $slideImage->save(String->format("Slide_%d.jpg", $sld->getSlideNumber()), ImageFormat::Jpeg);
      } finally {
        if (!java_is_null($slideImage)) {
          $slideImage->dispose();
        }
      }
    }
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

Render Comments when saving Presentation into Image

Aspose.Slides for PHP via Java provides a facility that allows you to render comments in a presentation’s slides when you are converting those slides into images. This PHP code demonstrates the operation:

  $pres = new Presentation("presentation.pptx");
  try {
    $notesOptions = new NotesCommentsLayoutingOptions();
    $notesOptions->setNotesPosition(NotesPositions::BottomTruncated);
    $opts = new RenderingOptions();
    $opts->setSlidesLayoutOptions($notesOptions);
    foreach($pres->getSlides() as $sld) {
      $slideImage = $sld->getImage($opts, new Java("java.awt.Dimension", 740, 960));
      try {
        $slideImage->save(String->format("Slide_%d.png", $sld->getSlideNumber()));
      } finally {
        if (!java_is_null($slideImage)) {
          $slideImage->dispose();
        }
      }
    }
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

See also

See other options to convert PPT/PPTX into image like: