个人开发日志2015-12-15
2015-12-15 21:21
225 查看
今天反复验证PPT转PDF失败原因
以下贴出关键源码
反复观察之后发现,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
以下贴出关键源码
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
相关文章推荐
- RFID扫描APP--source5
- php自己创建TPL模板引擎之初学习
- sys
- 电子商务网站专题页策划的6个必杀技
- ftp的20 21端口和主动被动模式
- Comparable与Comparator的区别
- ftp备份工具推荐,双向备份软件,文件同步软件,u盘备份软件推荐
- 由后缀数组构造字典序最小的原串
- Redis和Memcache的区别分析
- 58.UIView动画第二章(简单)
- IOS网络开发(二)
- 常用的正则表达式
- [转]adb shell dumpsys 命令
- 苹果ANCS协议学习【转】
- Packagist / Composer 中国全量镜像
- 【iCore3 双核心板】例程十四:FATFS实验——文件操作
- Codeforces 424C Magic Formulas
- RFID扫描APP--source4
- 苹果官方电池保护壳 让iPhone 6怀孕一只4S
- dom4j之xpath