利用LibreOffice转换ppt、doc转化pdf
利用LibreOffice转换ppt、doc转化pdf
LibreOffice下载地址: http://www.libreoffice.org/download/libreoffice-fresh/
jodconverter jar包下载:http://sourceforge.net/projects/jodconverter/files/JODConverter/
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.ConnectException;
import java.util.Date;
import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
public class Office2PDF {
public static int office2PDF(String sourceFile, String destFile) {
OpenOfficeConnection connection = null;
try {
File inputFile = new File(sourceFile);
if (!inputFile.exists()) {
return -1;//文件不存在
}
//文件夹不存在创建目录
File outputFile = new File(destFile);
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}
// connect to an OpenOffice.org instance running on port 8100
connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);
connection.connect();
// convert
DocumentConverter converter = new OpenOfficeDocumentConverter(
connection);
converter.convert(inputFile, outputFile);
return 0;
} catch (ConnectException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(connection!=null){
// close the connection
connection.disconnect();
}
}
return 1;
}
public static void main(String[] args){
Date startDate = new Date();
String sourceFile = "d:\\code\\alipay.ppt";
String destFile = "d:\\code\\change2.pdf";
System.out.println(Office2PDF.office2PDF(sourceFile, destFile));
Date endDate = new Date();
System.out.println("the cost time is "+(endDate.getTime()-startDate.getTime()));
}
}
先运行
soffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;"
soffice 在LibreOffice安装目录下
如果出现下面的异常
com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException: conversion failed: could not load input document
尽量使用最新的LibreOffice
利用LibreOffice转换ppt、doc转化pdf的更多相关文章
- Python实现doc转化pdf
Python实现doc转化pdf python源码实现doc转化pdf #-*- coding:utf-8 -*- # doc2pdf.py: python script to convert doc ...
- libreoffice转换文件为pdf文件乱码问题解决办法
最近系统需要一个office文件预览功能 解决方案为使用libreoffice将office文件转换为pdf文件,然后使用swftools将pdf文件转换为swf文件 最后在前台使用flexpaper ...
- 15个最好的PDF转word的在线转换器,将PDF文件转换成doc文件
PDF是一种文件格式,包含文本,图像,数据等,这是独立于操作系统的文件类型.它是一个开放的标准,压缩,另一方面DOC文件和矢量图形是由微软文字处理文件.该文件格式将纯文本格式转换为格式化文档.它支持几 ...
- Java使用Jacob将Word、Excel、PPT转化成PDF
使用Jacob将金山WPS转化成PDF,其中WPS文字使用KWPS.Aplication.Excel表格是KET.Application.演示文档是KWPP.Application,废话不多说,直接上 ...
- 【强大的PDF格式转换工具】Lighten PDF Converter OCR for Mac 6.2.0
[简介] Lighten PDF Converter OCR 是一款Mac上强大的PDF格式转换工具,可以将PDF文档快速批量的转换为Office (Word, Excel, PowerPoint), ...
- 使用python调用wps v9转换office文件到pdf
#!/usr/bin/python2.6 # -*- coding: utf-8 -*- # pip install timeout-decorator import os import win32c ...
- Java通过openOffice实现word,excel,ppt转成pdf实现在线预览
Java通过openOffice实现word,excel,ppt转成pdf实现在线预览 一.OpenOffice 1.1 下载地址 1.2 JodConverter 1.3 新建实体类PDFDemo ...
- 利用Swig转换C++代码为C#可用的代码
详细的文件路径为:http://user.qzone.qq.com/1259374136/blog/1432887689 Swig学习教程 1.Swig的基本介绍 SWIG(Simplified Wr ...
- [错误解决] Libreoffice转换不成功,直接不做任何操作
问题描述: Libreoffice在版本5.3.0之前都存在这个问题.现象是:当你运行其中一个LibreOffice的时候,再运行另外一个Libreoffice转换时,将不做任何操作. 解决方案: 如 ...
随机推荐
- .NET本质论(4)应用程序对象HttpApplication
当HttpContext对象创建之后,HttpRuntime将随后创建一个用于处理请求的对象,这个对象的类型为HttpApplication. 在ASP.NET内部,HttpRuntime管理一个定 ...
- velocity freemarker比较
相比较 FreeMarker 而言,Velocity 更加简单.轻量级,但它的功能却没有 FreeMarker 那么强大. 对于大部分的应用来说,使用 FreeMarker 比 Velocity 更简 ...
- Multithreading annd Grand Central Dispatch on ios for Beginners Tutorial-多线程和GCD的入门教程
原文链接:Multithreading and Grand Central Dispatch on iOS for Beginners Tutorial Have you ever written a ...
- 关于TCP协议握手的那些事儿
旁白 今天面了下鹅场的后台技术开发,面试官问了我关于TCP连接协议的3次握手和断开连接协议的4次握手的问题.因为之前看过TCP的连接和断开处理,但是印象没有那么深刻.我想主要原因是一直重复简单的记忆, ...
- hbase日常操作及维护
一,基本命令: 建表:create 'testtable','coulmn1','coulmn2' 也可以建表时加coulmn的属性如:create 'testtable',{NAME => ' ...
- CentOS学习笔记--目录配置
Linux目录配置 类Linux的目录看上去差不多,为什么? 以下内容节选自l 鸟哥的 Linux 私房菜 -- 基础学习篇目录 第六章.Linux 的文件权限与目录配置 3. Linux目录配 ...
- AeroSpike 资料
文档总览:http://www.aerospike.com/docs/ JAVA AeroSpike知识总览:http://www.aerospike.com/docs/client/java/sta ...
- HUE 忘记密码
解决方法: 启动HUE的Shell /opt/cloudera/parcels/CDH/lib/hue/build/env/bin/hue shell from django.contrib.auth ...
- ThinkPHP整合支付宝即时到账接口调用
首先是在支付宝的蚂蚁金服开放平台下载PHP的demo: https://doc.open.alipay.com/doc2/detail?treeId=62&articleId=103566&a ...
- win php nginx 配置小细节
win下配置php Nginx 首先 下载 php-Windows版本.下载Nginx Windows 版本 1> php.ini-production 修改为 php.ini 让其成为php的 ...