I want to be able to continuously add slides to a powerpoint while it is still open and not having to close it every time. I know its the FileOutputStream I just cant find a way to work around it.
// get snapshot of node scene and save to image
WritableImage snapshot = node.getScene().snapshot(null);
// create new slide show
File isFile = new File(pptName);
if(isFile.exists()){
ppt = new XMLSlideShow(new FileInputStream(pptName));
} else{
ppt = new XMLSlideShow();
}
// set the page size to match our screen size
ppt.setPageSize(Toolkit.getDefaultToolkit().getScreenSize());
// create slide
XSLFSlide slide = ppt.createSlide();
try {
// save temp image to disk
saveImage(imgName, snapshot);
// read the image file
pictureData = IOUtils.toByteArray(new FileInputStream(imgName));
// add the image to PPT
int idx = ppt.addPicture(pictureData,
XSLFPictureData.PICTURE_TYPE_PNG);
slide.createPicture(idx);
// save the PPT
pptFile = new FileOutputStream(pptName, true);
ppt.write(pptFile);
pptFile.close();
LOGGER.info("Saved to Powerpoint..");
// delete the temp image
deleteImage(imgName);
// open the PPT file in Powerpoint
openFileInApplication(pptName);
Here is a quick snippet. Once it reaches the FileOutputStream IF the powerpoint is still open it will throw a "file not found error". If I close the powerpoint then it'll add to the powerpoint and reopen it.
No comments:
Post a Comment