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,
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,
public static java.util.List convertPptToPng() {// save as PDF firstString localFolder=“D:\Aspose Data\”;String fileName=“microsoft-powerpoint”;boolean succeeded = false;// try as ppttry {Presentation pres = new Presentation(localFolder + fileName);pres.save(localFolder + fileName + “.pdf”, com.aspose.slides.SaveFormat.Pdf);succeeded = true;} catch (Throwable e) {}// try as pptxif (!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 PNGif (succeeded) {System.out.println(“Generated PDF as PPTX/PPT document: " + fileName);fileName = fileName + “.pdf”;return convertPdfToPng();}return null;}
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();}}