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/androidjava/com.aspose.slides/IImage#save(String formatName, int imageFormat)) method to save the slide thumbnail to the PNG format.

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

Presentation pres = new Presentation("pres.pptx");
try {
    for (int index = 0; index < pres.getSlides().size(); index++)
    {
        ISlide slide = pres.getSlides().get_Item(index);
        IImage slideImage = slide.getImage();
        try {
              slideImage.save("image_java_" + index + ".png", ImageFormat.Png);
        } finally {
             if (slideImage != null) slideImage.dispose();
        }
    }
} finally {
    if (pres != null) 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 in Java demonstrates the described operation:

Presentation pres = new Presentation("pres.pptx");
try {
    float scaleX = 2f;
    float scaleY = 2f;
    for (int index = 0; index < pres.getSlides().size(); index++)
    {
        ISlide slide = pres.getSlides().get_Item(index);
        IImage slideImage = slide.getImage(scaleX, scaleY);
        try {
              slideImage.save("image_java_" + index + ".png", ImageFormat.Png);
        } finally {
             if (slideImage != null) slideImage.dispose();
        }
    }
} finally {
    if (pres != null) 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:

Presentation pres = new Presentation("pres.pptx");
try {
    Dimension size = new Dimension(960, 720);
    for (int index = 0; index < pres.getSlides().size(); index++)
    {
        ISlide slide = pres.getSlides().get_Item(index);
        IImage slideImage = slide.getImage(size);
        try {
              slideImage.save("image_java_" + index + ".png", ImageFormat.Png);
        } finally {
             if (slideImage != null) slideImage.dispose();
        }
    }
} finally {
    if (pres != null) pres.dispose();
}