Convert ppt(x) to png

What is the correct way to convert a ppt(x) to a PNG/JPEG? I tried conversion to pdf and then to PNG but the document contents got lost. I am trying this code and it throws in the constructor.

Please advise on the correct usage of the API.


PresentationEx pres = new PresentationEx(localFolder + fileName);
// How to get slide count?
for (int i=1; i < 100; i++) {
Dimension d = new Dimension();
BufferedImage image = null;
try {
image = pres.getSlideById(i).getThumbnail(800, 800);
System.out.println(“got image…”);
} catch(Exception e) {
break;
}
if (image != null) {
String imageId = “sk-ppt-” + i;
ImageIO.write(image, “png”, new File(localFolder + imageId));
imageIdList.add(imageId);

} else {
System.out.println(“null…”);
}

}

Hi,


Thanks for inquiring Aspose.Slides.

I have observed the code sample shared by you and it seems OK. Please also visit this documentation link for your kind reference and give a try to our latest version Aspose.Slides for Java 6.7.1. If there is still an issue then please share the sample presentation along with generated corrupted output thumbnails. I will try to reproduce the issue further on my end to help you out.

Many Thanks,

I am attaching the ppt. My goal is to convert this to a png file. I convert ppt(x) to pdf, and then to png.



I think the issue lies in pdf to png conversion. The pdf converts fine.
But the conversion from pdf to png messes up the document.



private List convertPptToPng() {

// save as PDF first

boolean succeeded = false;

// try as ppt

try {

Presentation pres = new Presentation(localFolder + fileName);

pres.save(localFolder + fileName + “.pdf”, com.aspose.slides.export.SaveFormat.PDF);

succeeded = true;

} catch (Throwable e) {

}

// try as pptx

if (!succeeded) {

try {

PresentationEx pres = new PresentationEx(localFolder + fileName);

pres.save(localFolder + fileName + “.pdf”, com.aspose.slides.export.SaveFormat.PDF);

succeeded = true;

} catch (Throwable ex) {

}

}

// convert pdf to PNG

if (succeeded) {

System.out.println("Generated PDF as PPTX/PPT document: " + fileName);

fileName = fileName + “.pdf”;

return convertPdfToPng();





}



return null;

}



private List convertPdfToPng() {

List imageIdList = null;

try {

imageIdList = new ArrayList();

PdfConverter converter = new PdfConverter();

converter.bindPdf(localFolder + fileName);

converter.setResolution(100);

converter.doConvert();



int i = 0;

while (converter.hasNextImage()) {

// String imageId = generateUUID();

String imageId = “pdf-png-” + i++ + “.png”;

converter.getNextImage(localFolder + imageId, ImageType.PNG);

imageIdList.add(imageId);

}

System.out.println("Generated underlays as PDF file: " + fileName);

return imageIdList.size() == 0 ? null : imageIdList;

} catch (Throwable e) {



return null;

}

}




Hi,


I have observed the sample code shared along with the generated PDF and thumbnails. I like to suggest that you may please try using Aspose.Slides for Java 6.7.1 on your end using following modified code for generation of PDF. I also like to add that As far as Aspose.Slides is concerned, it is generating correct PDF. It may be an issue of PdfConverter end that is generating some issue in created PNG files.

public static java.util.List convertPptToPng() {
// save as PDF first
String localFolder=“D:\Aspose Data\”;
String fileName=“microsoft-powerpoint”;
boolean succeeded = false;
// try as ppt
try {
Presentation pres = new Presentation(localFolder + fileName);
pres.save(localFolder + fileName + “.pdf”, com.aspose.slides.SaveFormat.Pdf);
succeeded = true;
} catch (Throwable e) {
}
// try as pptx
if (!succeeded) {
try {
PresentationEx pres = new PresentationEx(localFolder + fileName);
pres.save(localFolder + fileName + “.pdf”, com.aspose.slides.SaveFormat.Pdf);
succeeded = true;
} catch (Throwable ex) {
}
}
// convert pdf to PNG
if (succeeded) {
System.out.println(“Generated PDF as PPTX/PPT document: " + fileName);
fileName = fileName + “.pdf”;
return convertPdfToPng();
}
return null;
}

I also like to sugges that Aspose.Slides for Java is also capable of generating slide thumbnail in PNG format. The following code will help you in achieving the goal. Please share, if I may help you further in this regard.

public static void PPTThumbnail(String path,String fileName)
{
try
{
Presentation pres = new Presentation(path+fileName+”.ppt");
double width=1000*(double)1/720;
double height=720*(double)1/540;
int j=1;
for(int i=1;i<=pres.getSlides().getLastSlidePosition();i++)
{
//Slide sld = pres.getSlides().get(i);
Slide sld = pres.getSlideByPosition(i);
BufferedImage image = sld.getThumbnail(1.0f, 1.0f);
ImageIO.write(image,“png”, new File(path+"/Slides/Slide_" + j + “.png”));
j++;
}
j=1;
}
catch(Exception e)
{
e.printStackTrace();
}

}

Many Thanks,