Hi,
We have ppt file with lot of chart objects embedded in the slide. When we are trying to create thumbnail from the slide object.
Issue is chart objects are disappears from the thumbnail.
For testing purpose we have attached ppt file and sample source code.
Please let me know your comments.
Thanks
Habibul Rahaman
Sample code :
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.TreeMap;
import javax.imageio.ImageIO;
import com.aspose.slides.License;
import com.aspose.slides.Placeholder;
import com.aspose.slides.Placeholders;
import com.aspose.slides.TextHolder;
public class TestPPT {
public static void main(String[] args) throws Exception {
String licenseFile = "Aspose.Slides.lic";
setLicense(licenseFile);
createPresentationSlides(new File("testpresentation.ppt"));
}
private static void setLicense(String fileName) {
FileInputStream fstream = null;
try {
// Create a stream object containing the license file
fstream = new FileInputStream(fileName);
// Instantiate the License class
License license = new License();
// Set the license through the stream object
license.setLicense(fstream);
} catch (Exception ex) {
ex.printStackTrace();
// Printing the exception, if it occurs
} finally {
// Closing the stream finally
if (fstream != null) {
try {
fstream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void createPresentationSlides(File pptFile) throws Exception {
FileInputStream fis = new FileInputStream( pptFile );
com.aspose.slides.Presentation srcPres = new com.aspose.slides.Presentation(fis);
int lastSlidePosition = srcPres.getSlides().getLastSlidePosition();
for (int i = 1; i <= lastSlidePosition; i++)
{
com.aspose.slides.Presentation newPres = new com.aspose.slides.Presentation();
newPres.setSlideSize(srcPres.getSlideSize());
// Clone the slide from source into new presentation
com.aspose.slides.Slide srcSld = srcPres.getSlideByPosition(i);
srcPres.cloneSlide(srcSld, 2, newPres, new TreeMap());
// Delete first empty slide
newPres.getSlides().remove(newPres.getSlideByPosition(1));
// Save created presentation with one slide to a new file
BufferedImage image = null;
try {
image = srcSld.getThumbnail(new Dimension(290, 230));
}catch(Exception e) {
System.out.println("Exception occurred while converting into thumbnail.");
}
File imgFile = new File("slide" + i + ".jpeg");
ImageIO.write(image, "JPEG", imgFile);
File slifile = new File("slide" + i + ".ppt");
FileOutputStream fos = new FileOutputStream(slifile);
newPres.write(fos);
fos.close();
String notes = "";
if(srcSld.getNotes() != null) {
notes = srcSld.getNotes().getText();
}
System.out.println("notes : " + notes);
Placeholders slidePHs = srcSld.getPlaceholders();
String text = "";
for (int j=0; j<slidePHs.size(); j++) {
Placeholder ph = slidePHs.get(j);
if (ph != null && ph instanceof TextHolder) {
TextHolder th = (TextHolder) ph;
if (th != null) {
text = text + th.getText() + " ";
}
}
}
System.out.println("text : " + text);
}
fis.close();
}
}