您的位置:首页 > 其它

个人开发日志2015-12-15

2015-12-15 21:21 225 查看
今天反复验证PPT转PDF失败原因

以下贴出关键源码

ppt = Dispatch.call(ppts,
"Open",
inputFile,
true,//ReadOnly
true,//Untitled指定文件是否有标题
false//WithWindow指定文件是否可见
).toDispatch();

Dispatch.call(ppt,
//             "SaveAs",
"ExportAsFixedFormat",
pdfFile,
ppSaveAsPDF
);


反复观察之后发现,jacob是通过com口与dll之间沟通的,但是ppt这个对象并没有SaveAs这个方法。

之后使用C#的方式,用Vistual Studio 2012 新建一个C#的工程,引入WPS的插件,wppapi.dll

在C#上编程,发现WPS提供的个人版不提供PPT转PDF的方法的接口。

在Android上也尝试了使用office=》html=》pdf的形式

//word 转 html
public static void convert2Html(String fileName, String outPutFile)
throws TransformerException, IOException,
ParserConfigurationException {

HWPFDocument wordDocument = new HWPFDocument(new FileInputStream(fileName));//WordToHtmlUtils.loadDoc(new FileInputStream(inputFile));

//兼容2007 以上版本
// XSSFWorkbook xssfwork=new XSSFWorkbook(new FileInputStream(fileName));
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(
DocumentBuilderFactory.newInstance().newDocumentBuilder()
.newDocument());
wordToHtmlConverter.setPicturesManager( new PicturesManager()
{
public String savePicture(byte[]
4000
content,
PictureType pictureType, String suggestedName,
float widthInches, float heightInches )
{
return "test/"+suggestedName;
}
} );
wordToHtmlConverter.processDocument(wordDocument);
//save pictures
List pics=wordDocument.getPicturesTable().getAllPictures();
if(pics!=null){
for(int i=0;i<pics.size();i++){
Picture pic = (Picture)pics.get(i);
System.out.println();
try {
pic.writeImageContent(new FileOutputStream(android.os.Environment.getExternalStorageDirectory().getPath() + File.separator + pic.suggestFullFileName()));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
Document htmlDocument = wordToHtmlConverter.getDocument();

ByteArrayOutputStream out = new ByteArrayOutputStream();
DOMSource domSource = new DOMSource(htmlDocument);
StreamResult streamResult = new StreamResult(out);

TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer = tf.newTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(OutputKeys.METHOD, "HTML");
serializer.transform(domSource, streamResult);
out.close();
writeFile(new String(out.toByteArray()), outPutFile);
}

发现office转html所使用的工具类,涉及到jform的类,后续如果想继续进行,可能需要修改Poi的源码,脱离jform
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: