我面临着一个问题,就像我使用apache POI生成pptx powerpoint演示文稿,所以生成的ppt是用天平办公室打开的,但当我试图在ms powerpoint中打开它时,它会产生一些问题,比如图像不能显示,这是我在演示文稿中插入的。我正在json数组中使用字节编码的字符串,我将其传递给我的service.Could有人能告诉我问题是什么吗?谢谢
服务
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();
} 发布于 2015-09-25 18:00:13
在JSONObject中,您似乎将参数作为二进制或输入流。确保您没有使用if条件获取null JSONObject。而且,你已经写道:
byte[] picture=Base64.decodeBase64(stringArray[i].substring(22));您将在字符串本身的开头剪切索引22处的字符串。确保以正确的方式读取字符串。因为你获取的二进制字符串可能会遗漏一些东西,而decryption是由于特定索引处的子字符串。即使你错过了一个字符,你的二进制字符串也没有任何意义。
https://stackoverflow.com/questions/32760252
复制相似问题