Trace_jr 2017-10-27 04:47
浏览 678

OPenpffice在linux下无转换

代码:
public class HtmlToPdfUtil {
private Logger logger = Logger.getLogger(this.getClass());

OpenOfficeConnection con = null;

//文件之间的转换
public void convert(File sourceFile, File _targetFile) {

    try {
        if (con == null) {
            con = new SocketOpenOfficeConnection(ip, port);
        }
        con.connect();
        DocumentConverter converter = new StreamOpenOfficeDocumentConverter(con);
         //DocumentConverter converter = new  OpenOfficeDocumentConverter(con);
        converter.convert(sourceFile, _targetFile);
        con.disconnect();
    } catch (Exception e) {
        logger.error("OpenOffice异常", e);
        try {
            if (con != null) {
                con.disconnect();
                con = null;
            }
        } catch (Exception e1) {
            logger.error(e);
        }
    }
}
// html文件生成pdf文件
public boolean htmlToPdf(String htmlPath,String pdfPath) {
    boolean flag = false;
    HtmlToPdfUtil openoffice = new HtmlToPdfUtil();
    openoffice.convert(new File(htmlPath), new File(pdfPath));
    flag = true;
    return flag;
}
/**
 * 删除文件的工具
 * @param url
 */
public void deleFile(String url){
    File file = new File(url);

    if(file.exists()){
    //    file.delete();
    }
}
/**
 * 思路:
 *  1、生成静态页面落地,返回生成静态页面的url;
 *  2、指定生成pdf文件的url;
 *  3、讲html转换为pdf;
 *  4、删除生成的静态页面,留取需要的pdf文件;
 * 结束
 */
public static void main(String[] args) {
    //生成的静态页的文件目录
    String inPath = "C:\\html\\hello.html";//输入路径(输入html文件的路径)
    //转换成pdf文件的目录
    String outPath = "C:\\pdf\\hello.pdf";//输出路径(转换为pdf的路径)
    HtmlToPdfUtil htw = new HtmlToPdfUtil();
    htw.convert(new File(inPath), new File(outPath));
    //删除静态页
    htw.deleFile(inPath);
}
/****************************** 测试**********************************************/
public void setIp(String ip) {
    this.ip = ip;
}
public void setPort(int port) {
    this.port = port;
}
private String ip = "172.16.2.49";
//是不是用队列模拟生成端口号,因为主要是连接端口号的问题。
private int port = 8100;

}
报错:
图片说明

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法