【发布时间】:2015-09-24 11:31:54
【问题描述】:
我面临一个问题,比如我使用 apache POI 来生成 pptx PowerPoint 演示文稿,因此生成的 ppt 可以通过 Libra Office 打开,但是当我尝试在 ms PowerPoint 中打开时,它会产生一些问题,例如无法显示图像,这我插入了演示文稿。我在 json 数组中获取字节编码字符串,并将它传递给我的 服务。有人可以帮我解决什么问题吗?谢谢
服务
public Response generatePptDocument(JSONObject json) throws JSONException{
JSONArray jsonArray=json.getJSONArray("image");
String [] stringArray=new String[jsonArray.length()];
XMLSlideShow ppt = new XMLSlideShow();
Response result=null;
String uniquename=null;
try{
for(int i=0;i<jsonArray.length();i++){
XSLFSlide slide = ppt.createSlide();
stringArray[i]=(String) jsonArray.get(i);
byte[] picture=Base64.decodeBase64(stringArray[i].substring(22));
int idx = ppt.addPicture(picture, XSLFPictureData.PICTURE_TYPE_PNG);
ppt.setPageSize(new java.awt.Dimension(1600, 600));
//creating a slide with given picture on it
XSLFPictureShape pic = slide.createPicture(idx);
String outputDirectory = propertyUtil.getProperty("output.save.uri");
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("ddMMyyyyHHmmss");
String date = DATE_FORMAT.format(new Date());
uniquename = 1 + "-" + date + "." + "pptx";
String streamPath = outputDirectory+uniquename;
//creating a file object
File file=new File(streamPath);
FileOutputStream out = new FileOutputStream(file);
//saving the changes to a file
ppt.write(out);
StringResponse response=new StringResponse();
response.setUniqueName(uniquename);
result=Response.ok().entity(response).build();
}
}catch(JSONException e){
log.info("Error in json Object");
result=Response.status(304).entity("Error in json Object").build();
}
catch(IOException e){
log.info("Error while creating PPT Document");
result=Response.status(304).entity("Error while generation PPT").build();
}
【问题讨论】:
标签: java apache-poi