string(7723) "{"docs":[{"id":"158579","text":"\u3010Python\u3011Tkinter\u56fe\u5f62\u754c\u9762\u8bbe\u8ba1\uff08GUI\uff09","intro":"\u76ee\u5f55\n\nECharts\n\u5f02\u6b65\u52a0\u8f7d\n\n\n\nECharts\r\n\u6570\u636e\u53ef\u89c6\u5316\u5728\u8fc7\u53bb\u51e0\u5e74\u4e2d\u53d6\u5f97\u4e86\u5de8\u5927\u8fdb\u5c55\u3002\u5f00\u53d1\u4eba\u5458\u5bf9\u53ef\u89c6\u5316\u4ea7\u54c1\u7684\u671f\u671b\u4e0d\u518d\u662f\u7b80\u5355\u7684\u56fe\u8868\u521b\u5efa\u5de5\u5177\uff0c\u800c\u662f\u5728\u4ea4\u4e92\u3001\u6027\u80fd\u3001\u6570\u636e\u5904\u7406\u7b49\u65b9\u9762\u6709\u66f4\u9ad8\u7684\u8981\u6c42\u3002\r\nchart.setOption({\r\n color: [\r\n ","username":"HGNET","tagsname":"","tagsid":"","catesname":"","catesid":"","createtime":"1641183196","_id":"158579"},{"id":"158620","text":"python\u4e4bgui-tkinter\u53ef\u89c6\u5316\u7f16\u8f91\u754c\u9762 \u81ea\u52a8\u751f\u6210\u4ee3\u7801","intro":"\u76ee\u5f55\n\nECharts\n\u5f02\u6b65\u52a0\u8f7d\n\n\n\nECharts\r\n\u6570\u636e\u53ef\u89c6\u5316\u5728\u8fc7\u53bb\u51e0\u5e74\u4e2d\u53d6\u5f97\u4e86\u5de8\u5927\u8fdb\u5c55\u3002\u5f00\u53d1\u4eba\u5458\u5bf9\u53ef\u89c6\u5316\u4ea7\u54c1\u7684\u671f\u671b\u4e0d\u518d\u662f\u7b80\u5355\u7684\u56fe\u8868\u521b\u5efa\u5de5\u5177\uff0c\u800c\u662f\u5728\u4ea4\u4e92\u3001\u6027\u80fd\u3001\u6570\u636e\u5904\u7406\u7b49\u65b9\u9762\u6709\u66f4\u9ad8\u7684\u8981\u6c42\u3002\r\nchart.setOption({\r\n color: [\r\n ","username":"darkspr","tagsname":"","tagsid":"","catesname":"","catesid":"","createtime":"1641183190","_id":"158620"},{"id":"158603","text":"python3.6 +tkinter GUI\u7f16\u7a0b \u5b9e\u73b0\u754c\u9762\u5316\u7684\u6587\u672c\u5904\u7406\u5de5\u5177","intro":"\u76ee\u5f55\n\nECharts\n\u5f02\u6b65\u52a0\u8f7d\n\n\n\nECharts\r\n\u6570\u636e\u53ef\u89c6\u5316\u5728\u8fc7\u53bb\u51e0\u5e74\u4e2d\u53d6\u5f97\u4e86\u5de8\u5927\u8fdb\u5c55\u3002\u5f00\u53d1\u4eba\u5458\u5bf9\u53ef\u89c6\u5316\u4ea7\u54c1\u7684\u671f\u671b\u4e0d\u518d\u662f\u7b80\u5355\u7684\u56fe\u8868\u521b\u5efa\u5de5\u5177\uff0c\u800c\u662f\u5728\u4ea4\u4e92\u3001\u6027\u80fd\u3001\u6570\u636e\u5904\u7406\u7b49\u65b9\u9762\u6709\u66f4\u9ad8\u7684\u8981\u6c42\u3002\r\nchart.setOption({\r\n color: [\r\n ","username":"chenyuebai","tagsname":"","tagsid":"","catesname":"","catesid":"","createtime":"1641183187","_id":"158603"},{"id":"27850","text":"Python GUI\u4e4btkinter\u7a97\u53e3\u89c6\u7a97\u6559\u7a0b\u5927\u96c6\u5408\uff08\u770b\u8fd9\u7bc7\u5c31\u591f\u4e86\uff09 - \u6d2a\u536b","intro":"\u76ee\u5f55\n\nECharts\n\u5f02\u6b65\u52a0\u8f7d\n\n\n\nECharts\r\n\u6570\u636e\u53ef\u89c6\u5316\u5728\u8fc7\u53bb\u51e0\u5e74\u4e2d\u53d6\u5f97\u4e86\u5de8\u5927\u8fdb\u5c55\u3002\u5f00\u53d1\u4eba\u5458\u5bf9\u53ef\u89c6\u5316\u4ea7\u54c1\u7684\u671f\u671b\u4e0d\u518d\u662f\u7b80\u5355\u7684\u56fe\u8868\u521b\u5efa\u5de5\u5177\uff0c\u800c\u662f\u5728\u4ea4\u4e92\u3001\u6027\u80fd\u3001\u6570\u636e\u5904\u7406\u7b49\u65b9\u9762\u6709\u66f4\u9ad8\u7684\u8981\u6c42\u3002\r\nchart.setOption({\r\n color: [\r\n ","username":"shwee","tagsname":"","tagsid":"","catesname":"","catesid":"","createtime":"1641183186","_id":"27850"},{"id":"158605","text":"Python GUI\u7f16\u7a0b(Tkinter) windows\u754c\u9762\u5f00\u53d1","intro":"\u76ee\u5f55\n\nECharts\n\u5f02\u6b65\u52a0\u8f7d\n\n\n\nECharts\r\n\u6570\u636e\u53ef\u89c6\u5316\u5728\u8fc7\u53bb\u51e0\u5e74\u4e2d\u53d6\u5f97\u4e86\u5de8\u5927\u8fdb\u5c55\u3002\u5f00\u53d1\u4eba\u5458\u5bf9\u53ef\u89c6\u5316\u4ea7\u54c1\u7684\u671f\u671b\u4e0d\u518d\u662f\u7b80\u5355\u7684\u56fe\u8868\u521b\u5efa\u5de5\u5177\uff0c\u800c\u662f\u5728\u4ea4\u4e92\u3001\u6027\u80fd\u3001\u6570\u636e\u5904\u7406\u7b49\u65b9\u9762\u6709\u66f4\u9ad8\u7684\u8981\u6c42\u3002\r\nchart.setOption({\r\n color: [\r\n ","username":"itfat","tagsname":"","tagsid":"","catesname":"","catesid":"","createtime":"1641183184","_id":"158605"},{"id":"28228","text":"tkinter python\uff08\u56fe\u5f62\u5f00\u53d1\u754c\u9762\uff09","intro":"\u76ee\u5f55\n\nECharts\n\u5f02\u6b65\u52a0\u8f7d\n\n\n\nECharts\r\n\u6570\u636e\u53ef\u89c6\u5316\u5728\u8fc7\u53bb\u51e0\u5e74\u4e2d\u53d6\u5f97\u4e86\u5de8\u5927\u8fdb\u5c55\u3002\u5f00\u53d1\u4eba\u5458\u5bf9\u53ef\u89c6\u5316\u4ea7\u54c1\u7684\u671f\u671b\u4e0d\u518d\u662f\u7b80\u5355\u7684\u56fe\u8868\u521b\u5efa\u5de5\u5177\uff0c\u800c\u662f\u5728\u4ea4\u4e92\u3001\u6027\u80fd\u3001\u6570\u636e\u5904\u7406\u7b49\u65b9\u9762\u6709\u66f4\u9ad8\u7684\u8981\u6c42\u3002\r\nchart.setOption({\r\n color: [\r\n ","username":"yudanqu","tagsname":"","tagsid":"","catesname":"","catesid":"","createtime":"1641183159","_id":"28228"},{"id":"158613","text":"Tkinter\u56fe\u5f62\u754c\u9762\u8bbe\u8ba1\uff08GUI\uff09","intro":"\u76ee\u5f55\n\nECharts\n\u5f02\u6b65\u52a0\u8f7d\n\n\n\nECharts\r\n\u6570\u636e\u53ef\u89c6\u5316\u5728\u8fc7\u53bb\u51e0\u5e74\u4e2d\u53d6\u5f97\u4e86\u5de8\u5927\u8fdb\u5c55\u3002\u5f00\u53d1\u4eba\u5458\u5bf9\u53ef\u89c6\u5316\u4ea7\u54c1\u7684\u671f\u671b\u4e0d\u518d\u662f\u7b80\u5355\u7684\u56fe\u8868\u521b\u5efa\u5de5\u5177\uff0c\u800c\u662f\u5728\u4ea4\u4e92\u3001\u6027\u80fd\u3001\u6570\u636e\u5904\u7406\u7b49\u65b9\u9762\u6709\u66f4\u9ad8\u7684\u8981\u6c42\u3002\r\nchart.setOption({\r\n color: [\r\n ","username":"pywjh","tagsname":"","tagsid":"","catesname":"","catesid":"","createtime":"1641183158","_id":"158613"},{"id":"341361","text":"\u91cf\u5316\u5206\u6790\u83b7\u53d6\u6570\u636e\u76843\u79cd\u59ff\u52bf\uff08\u538b\u7bb1\u5e95\u7684\u795e\u5668Tushare\uff09","intro":"\u76ee\u5f55\n\nECharts\n\u5f02\u6b65\u52a0\u8f7d\n\n\n\nECharts\r\n\u6570\u636e\u53ef\u89c6\u5316\u5728\u8fc7\u53bb\u51e0\u5e74\u4e2d\u53d6\u5f97\u4e86\u5de8\u5927\u8fdb\u5c55\u3002\u5f00\u53d1\u4eba\u5458\u5bf9\u53ef\u89c6\u5316\u4ea7\u54c1\u7684\u671f\u671b\u4e0d\u518d\u662f\u7b80\u5355\u7684\u56fe\u8868\u521b\u5efa\u5de5\u5177\uff0c\u800c\u662f\u5728\u4ea4\u4e92\u3001\u6027\u80fd\u3001\u6570\u636e\u5904\u7406\u7b49\u65b9\u9762\u6709\u66f4\u9ad8\u7684\u8981\u6c42\u3002\r\nchart.setOption({\r\n color: [\r\n ","username":"casual","tagsname":"","tagsid":"","catesname":"","catesid":"","createtime":"1641183069","_id":"341361"},{"id":"238879","text":"\u9762\u5411\u4ea4\u6613\u7684\u65e5\u5185\u9ad8\u9891\u91cf\u5316\u4ea4\u6613\u5e73\u53f0\u7b14\u8bb0","intro":"\u76ee\u5f55\n\nECharts\n\u5f02\u6b65\u52a0\u8f7d\n\n\n\nECharts\r\n\u6570\u636e\u53ef\u89c6\u5316\u5728\u8fc7\u53bb\u51e0\u5e74\u4e2d\u53d6\u5f97\u4e86\u5de8\u5927\u8fdb\u5c55\u3002\u5f00\u53d1\u4eba\u5458\u5bf9\u53ef\u89c6\u5316\u4ea7\u54c1\u7684\u671f\u671b\u4e0d\u518d\u662f\u7b80\u5355\u7684\u56fe\u8868\u521b\u5efa\u5de5\u5177\uff0c\u800c\u662f\u5728\u4ea4\u4e92\u3001\u6027\u80fd\u3001\u6570\u636e\u5904\u7406\u7b49\u65b9\u9762\u6709\u66f4\u9ad8\u7684\u8981\u6c42\u3002\r\nchart.setOption({\r\n color: [\r\n ","username":"TaiYangXiManYouZhe","tagsname":"","tagsid":"","catesname":"","catesid":"","createtime":"1641183067","_id":"238879"},{"id":"238890","text":"2021 \u6700\u65b0\u91cf\u5316\u6295\u8d44\u4ea4\u6613\u8d44\u6e90\u6c47\u603b","intro":"\u76ee\u5f55\n\nECharts\n\u5f02\u6b65\u52a0\u8f7d\n\n\n\nECharts\r\n\u6570\u636e\u53ef\u89c6\u5316\u5728\u8fc7\u53bb\u51e0\u5e74\u4e2d\u53d6\u5f97\u4e86\u5de8\u5927\u8fdb\u5c55\u3002\u5f00\u53d1\u4eba\u5458\u5bf9\u53ef\u89c6\u5316\u4ea7\u54c1\u7684\u671f\u671b\u4e0d\u518d\u662f\u7b80\u5355\u7684\u56fe\u8868\u521b\u5efa\u5de5\u5177\uff0c\u800c\u662f\u5728\u4ea4\u4e92\u3001\u6027\u80fd\u3001\u6570\u636e\u5904\u7406\u7b49\u65b9\u9762\u6709\u66f4\u9ad8\u7684\u8981\u6c42\u3002\r\nchart.setOption({\r\n color: [\r\n ","username":"xgqfrms","tagsname":"","tagsid":"","catesname":"","catesid":"","createtime":"1641183063","_id":"238890"}],"count":535118}" array(2) { ["docs"]=> array(10) { [0]=> array(10) { ["id"]=> string(6) "158579" ["text"]=> string(46) "【Python】Tkinter图形界面设计(GUI)" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(5) "HGNET" ["tagsname"]=> string(0) "" ["tagsid"]=> string(0) "" ["catesname"]=> string(0) "" ["catesid"]=> string(0) "" ["createtime"]=> string(10) "1641183196" ["_id"]=> string(6) "158579" } [1]=> array(10) { ["id"]=> string(6) "158620" ["text"]=> string(60) "python之gui-tkinter可视化编辑界面 自动生成代码" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "darkspr" ["tagsname"]=> string(0) "" ["tagsid"]=> string(0) "" ["catesname"]=> string(0) "" ["catesid"]=> string(0) "" ["createtime"]=> string(10) "1641183190" ["_id"]=> string(6) "158620" } [2]=> array(10) { ["id"]=> string(6) "158603" ["text"]=> string(66) "python3.6 +tkinter GUI编程 实现界面化的文本处理工具" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(10) "chenyuebai" ["tagsname"]=> string(0) "" ["tagsid"]=> string(0) "" ["catesname"]=> string(0) "" ["catesid"]=> string(0) "" ["createtime"]=> string(10) "1641183187" ["_id"]=> string(6) "158603" } [3]=> array(10) { ["id"]=> string(5) "27850" ["text"]=> string(80) "Python GUI之tkinter窗口视窗教程大集合(看这篇就够了) - 洪卫" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(5) "shwee" ["tagsname"]=> string(0) "" ["tagsid"]=> string(0) "" ["catesname"]=> string(0) "" ["catesid"]=> string(0) "" ["createtime"]=> string(10) "1641183186" ["_id"]=> string(5) "27850" } [4]=> array(10) { ["id"]=> string(6) "158605" ["text"]=> string(45) "Python GUI编程(Tkinter) windows界面开发" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(5) "itfat" ["tagsname"]=> string(0) "" ["tagsid"]=> string(0) "" ["catesname"]=> string(0) "" ["catesid"]=> string(0) "" ["createtime"]=> string(10) "1641183184" ["_id"]=> string(6) "158605" } [5]=> array(10) { ["id"]=> string(5) "28228" ["text"]=> string(39) "tkinter python(图形开发界面)" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "yudanqu" ["tagsname"]=> string(0) "" ["tagsid"]=> string(0) "" ["catesname"]=> string(0) "" ["catesid"]=> string(0) "" ["createtime"]=> string(10) "1641183159" ["_id"]=> string(5) "28228" } [6]=> array(10) { ["id"]=> string(6) "158613" ["text"]=> string(34) "Tkinter图形界面设计(GUI)" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(5) "pywjh" ["tagsname"]=> string(0) "" ["tagsid"]=> string(0) "" ["catesname"]=> string(0) "" ["catesid"]=> string(0) "" ["createtime"]=> string(10) "1641183158" ["_id"]=> string(6) "158613" } [7]=> array(10) { ["id"]=> string(6) "341361" ["text"]=> string(68) "量化分析获取数据的3种姿势(压箱底的神器Tushare)" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(6) "casual" ["tagsname"]=> string(0) "" ["tagsid"]=> string(0) "" ["catesname"]=> string(0) "" ["catesid"]=> string(0) "" ["createtime"]=> string(10) "1641183069" ["_id"]=> string(6) "341361" } [8]=> array(10) { ["id"]=> string(6) "238879" ["text"]=> string(51) "面向交易的日内高频量化交易平台笔记" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(18) "TaiYangXiManYouZhe" ["tagsname"]=> string(0) "" ["tagsid"]=> string(0) "" ["catesname"]=> string(0) "" ["catesid"]=> string(0) "" ["createtime"]=> string(10) "1641183067" ["_id"]=> string(6) "238879" } [9]=> array(10) { ["id"]=> string(6) "238890" ["text"]=> string(41) "2021 最新量化投资交易资源汇总" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "xgqfrms" ["tagsname"]=> string(0) "" ["tagsid"]=> string(0) "" ["catesname"]=> string(0) "" ["catesid"]=> string(0) "" ["createtime"]=> string(10) "1641183063" ["_id"]=> string(6) "238890" } } ["count"]=> int(535118) } Java中几种office文档转pdf的方式 - 爱码网
excellencesy

最近公司要做office的文档,搜集了几种office文档转pdf的方式,简单的做下总结

我主要尝试了三种方式:openoffice,aspose,jacob

对他们进行了大文件,小文件,在linux,在windows,转换txt,excel,word,ppt的测试。

一、aspose:这种方式在目前来看应该是最好的,无论是转换的速度还是成功的概率,还支持的文件类型。

(1)使用:

这种方式使用很简单,引入jar包就可以直接使用

代码:

源码,jar包在最后提供

package aspose;

import java.io.*;

import javax.servlet.http.HttpServletRequest;

import com.aspose.cells.Workbook;
import com.aspose.slides.Presentation;
import com.aspose.slides.SaveFormat;
import com.aspose.words.*;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter;

public class AsposeUtil {

    //校验license
    private static boolean judgeLicense() {
        boolean result = false;
        try {
            InputStream is = AsposeUtil.class.getClassLoader().getResourceAsStream("license.xml");
            License aposeLic = new License();
            aposeLic.setLicense(is);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    // 转换
    public static void trans(String filePath, String pdfPath, String type) {
        if (!judgeLicense()) {
            System.out.println("license错误");
        }
        try {
            System.out.println("as开始:" + filePath);
            long old = System.currentTimeMillis();
            File file = new File(pdfPath);
            toPdf(file, filePath, type);
            long now = System.currentTimeMillis();
            System.out.println("完成:" + pdfPath);
            System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }

    private static void toPdf(File file, String filePath, String type) {
        if ("word".equals(type) || "txt".equals(type)) {
            wordofpdf(file, filePath);
        } else if ("excel".equals(type)) {
            exceOfPdf(file, filePath);
        } else if ("ppt".equals(type)) {
            pptofpdf(file, filePath);
        }else{
            System.out.println("暂不支持该类型:"+type);
        }
    }

    private static void wordofpdf(File file, String filePath) {
        FileOutputStream os = null;
        Document doc;
        try {
            os = new FileOutputStream(file);
            doc = new Document(filePath);
            doc.save(os, com.aspose.words.SaveFormat.PDF);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void exceOfPdf(File file, String filePath) {
        FileOutputStream os = null;
        try {
            os = new FileOutputStream(file);
            Workbook wb = new Workbook(filePath);
            wb.save(os, com.aspose.cells.SaveFormat.PDF);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void pptofpdf(File file, String filePath) {
        FileOutputStream os = null;
        try {
            os = new FileOutputStream(file);
            Presentation pres = new Presentation(filePath);// 输入pdf路径
            pres.save(os, SaveFormat.Pdf);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

}

测试代码:

 这里面每一种类型的文档都至少取了三个,主要是为了测试他们对大文件,小文件的支持,从而能在不同的场景更好的选择使用的方式,在本篇文章的最后会将测试的结果贴上

package openoffice;

import aspose.AsposeUtil;

/**
 * @author sonyan
 * @version 2019年9月25日 下午1:12:21
 * @desc
 */
public class Test {

    private static void testWord(String path_word, String pafpath) throws Exception {
        String word1 = path_word + "01正方数字.docx";
        String word2 = path_word + "02正方数字.docx";
        String word3 = path_word + "03正方数字.doc";
        String word4 = path_word + "04正方数字.doc";
        String word5 = path_word + "05正方数字.docx";
        String word6 = path_word + "06正方数字.doc";

        OpenOfficeUtils.toPdf(word1, pafpath + "Open-word-01测试.pdf");
        OpenOfficeUtils.toPdf(word2, pafpath + "Open-word-02测试.pdf");
        OpenOfficeUtils.toPdf(word3, pafpath + "Open-word-03测试.pdf");
        OpenOfficeUtils.toPdf(word4, pafpath + "Open-word-04测试.pdf");
        OpenOfficeUtils.toPdf(word5, pafpath + "Open-word-05测试.pdf");
        OpenOfficeUtils.toPdf(word6, pafpath + "Open-word-06测试.pdf");

    }

    private static void testWord2(String path_word, String pafpath) throws Exception {
        String word1 = path_word + "01.docx";
        String word2 = path_word + "02.docx";
        String word3 = path_word + "03.doc";
        String word4 = path_word + "04.doc";
        String word5 = path_word + "05.docx";
        String word6 = path_word + "06.doc";

        OpenOfficeUtils.toPdf(word1, pafpath + "Open-word-01.pdf");
        OpenOfficeUtils.toPdf(word2, pafpath + "Open-word-02.pdf");
        OpenOfficeUtils.toPdf(word3, pafpath + "Open-word-03.pdf");
        OpenOfficeUtils.toPdf(word4, pafpath + "Open-word-04.pdf");
        OpenOfficeUtils.toPdf(word5, pafpath + "Open-word-05.pdf");
        OpenOfficeUtils.toPdf(word6, pafpath + "Open-word-06.pdf");

    }

    private static void testTxt(String path_word, String pafpath) throws Exception {
        String txt1 = path_word + "01jvm.txt";
        String txt2 = path_word + "02jvm.txt";
        String txt3 = path_word + "03jvm.txt";

        OpenOfficeUtils.toPdf(txt1, pafpath + "Open-txt-01测试.pdf");
        OpenOfficeUtils.toPdf(txt2, pafpath + "Open-txt-02测试.pdf");
        OpenOfficeUtils.toPdf(txt3, pafpath + "Open-txt-03测试.pdf");
    }

    private static void testTxt2(String path_word, String pafpath) throws Exception {
        String txt1 = path_word + "01jvm.txt";
        String txt2 = path_word + "02jvm.txt";
        String txt3 = path_word + "03jvm.txt";

        OpenOfficeUtils.toPdf(txt1, pafpath + "Open-txt-01.pdf");
        OpenOfficeUtils.toPdf(txt2, pafpath + "Open-txt-02.pdf");
        OpenOfficeUtils.toPdf(txt3, pafpath + "Open-txt-03.pdf");
    }

    private static void testExcel(String path_word, String pafpath) throws Exception {
        String txt1 = path_word + "01部门开发任务管理.xlsx";
        String txt2 = path_word + "02部门开发任务管理.xlsx";
        String txt3 = path_word + "03部门开发任务管理.xlsx";

        OpenOfficeUtils.toPdf(txt1, pafpath + "Open-excel-01测试.pdf");
        OpenOfficeUtils.toPdf(txt2, pafpath + "Open-excel-02测试.pdf");
        OpenOfficeUtils.toPdf(txt3, pafpath + "Open-excel-03测试.pdf");
    }

    private static void testExcel2(String path_word, String pafpath) throws Exception {
        String txt1 = path_word + "01.xlsx";
        String txt2 = path_word + "02.xlsx";
        String txt3 = path_word + "03.xlsx";

        OpenOfficeUtils.toPdf(txt1, pafpath + "Open-excel-01.pdf");
        OpenOfficeUtils.toPdf(txt2, pafpath + "Open-excel-02.pdf");
        OpenOfficeUtils.toPdf(txt3, pafpath + "Open-excel-03.pdf");
    }

    private static void testPPt(String path_ppt, String pafpath) throws Exception {
        String txt1 = path_ppt + "01jquery培训.pptx";
        String txt2 = path_ppt + "02jquery培训.pptx";
        String txt3 = path_ppt + "03jquery培训.ppt";

        OpenOfficeUtils.toPdf(txt1, pafpath + "Open-ppt-01测试.pdf");
        OpenOfficeUtils.toPdf(txt2, pafpath + "Open-ppt-02测试.pdf");
        OpenOfficeUtils.toPdf(txt3, pafpath + "Open-ppt-03测试.pdf");
    }

    private static void testPPt2(String path_ppt, String pafpath) throws Exception {
        String txt1 = path_ppt + "01jquery.pptx";
        String txt2 = path_ppt + "02jquery.pptx";
        String txt3 = path_ppt + "03jquery培训.ppt";

        OpenOfficeUtils.toPdf(txt1, pafpath + "Open-ppt-01.pdf");
        OpenOfficeUtils.toPdf(txt2, pafpath + "Open-ppt-02.pdf");
        OpenOfficeUtils.toPdf(txt3, pafpath + "Open-ppt-03.pdf");
    }

    public static void LinuxTest() throws Exception {
        String path_word = "/software/songyan/hah/01word/";
        String path_txt = "/software/songyan/hah/02txt/";
        String path_excel = "/software/songyan/hah/03excel/";
        String path_ppt = "/software/songyan/hah/04ppt/";
        String pafpath = "/software/songyan/hah/pdf/";

        System.out.println("************************");
        testTxt(path_txt, pafpath);
        System.out.println("************************");
        testExcel(path_excel, pafpath);
        System.out.println("************************");
        testPPt(path_ppt, pafpath);
        System.out.println("************************");
        testWord(path_word, pafpath);
    }

    public static void LinuxTest2() throws Exception {
        String path_word = "/software/songyan/hah/01word/";
        String path_txt = "/software/songyan/hah/02txt/";
        String path_excel = "/software/songyan/hah/03excel/";
        String path_ppt = "/software/songyan/hah/04ppt/";
        String pafpath = "/software/songyan/hah/pdf/";

        System.out.println("************************");
        testTxt2(path_txt, pafpath);
        System.out.println("************************");
        testExcel2(path_excel, pafpath);
        System.out.println("************************");
        testPPt2(path_ppt, pafpath);
        System.out.println("************************");
        testWord2(path_word, pafpath);
    }

    public static void winTest() throws Exception {
        String path_word = "C:/Users/Administrator.DESKTOP-QN9A3AA/Desktop/office/测试文档/转换前文档/01word/";
        String path_txt = "C:/Users/Administrator.DESKTOP-QN9A3AA/Desktop/office/测试文档/转换前文档/02txt/";
        String path_excel = "C:/Users/Administrator.DESKTOP-QN9A3AA/Desktop/office/测试文档/转换前文档/03excel/";
        String path_ppt = "C:/Users/Administrator.DESKTOP-QN9A3AA/Desktop/office/测试文档/转换前文档/04ppt/";
        String pafpath = "C:/Users/Administrator.DESKTOP-QN9A3AA/Desktop/office/测试文档/pdf/";

        System.out.println("************************");
        testWord(path_word, pafpath);
        System.out.println("************************");
        testTxt(path_txt, pafpath);
        System.out.println("************************");
        testExcel(path_excel, pafpath);
        System.out.println("************************");
        testPPt(path_ppt, pafpath);
    }
    
    public static void main(String[] args) throws Exception {
        winTest();
    }
}
View Code

 

 (2)初次使用遇到的问题:

  1)我在这种方式的初次尝试中走的最大的一个坑就是:jar包的引入

  

   

  

上面这三个分别是转换word/txt,excel,ppt的关键代码,在网上找的很多代码可能都是对一种方式的转换,所以SaveFormat也就不会加上包名,所以我在开始就以为是同一个类,怎么调试都不对,最后也是不记得看了哪个博友的博客才注意到这,一定要加上包名,这三个不同包下的类来自三个不同的jar包

 

 2)还有一个很大的坑就是在linux系统上部署测试的时候报了下面的错

 这个问题就查到了一个结果,官方给出的解释是:

 

也就是缺少jar包,可是我检查后发现jar包引入的也没有错误,在第二天找同事帮忙的时候发现,同样的war包使用他的工具可以正常执行转换

很不可思议,我们是在同一台服务器上上传的相同的war包,不一样的就是使用的工具不一样,我用的xshell,他用的sshClient。

我有又测试了一下,第一次访问的时候都会有这个提示

 要求安装xmanager,然后就试了试,安装之后果然就可以了,原因现在也没搞明白,,知道的留言吧(我们经理说可能是依赖xmanager里面的包,只是一种猜测)

3)还有个小问题就是:在linux上使用的时候需要安装字体,不安装会中文乱码,这里不细说,百度很多,操作很简单

4)在测试的过程中有个ppt文件转换失败,目前还没有找到原因,转换失败的文件在最后也会提供在网盘中。。

5)这种方式不支持中文路径,如果转换的文件里面有中文,就会报文件找不到的错误

二,openoffice方式:这种方式在转小文件的时候还是很好用的,在调研的过程中也发现不少公司在实际开发中就是使用的这种方式,我们公司在之前也是用的这种,但是在文件太大的时候转换的时间就会特别的慢,几十分钟的那种。而且这种方式需要依赖openoffice

(1)代码

注:这种方式需要安装openoffice,使用前需要开启openoffice,在转换大文件的时候速度特别的慢。

使用步骤

(1)安装openoffice

(2)开启openoffice

(3)调用代码

package openoffice; 

import java.io.File;
import java.net.ConnectException;

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;
import com.artofsolving.jodconverter.openoffice.converter.StreamOpenOfficeDocumentConverter;


public class OpenOfficeUtils {

    static final String host = "192.168.11.3";//openoffice服务地址
    static final int post = 8100;//openoffice端口号
    
    //计时
      public static void toPdf(String filePath, String pdfPath) {
          try {
              long old = System.currentTimeMillis();
              System.out.println("open-开始:" + filePath);
              File wordFile = new File(filePath);
            File PDFFile = new File(pdfPath);
            OpenOfficeConnection connection = new SocketOpenOfficeConnection(host, post);
            try {
                connection.connect();
                DocumentConverter converter = getConverter(host, connection);
                converter.convert(wordFile, PDFFile);
                long now = System.currentTimeMillis();
                  System.out.println("open-完成:" + filePath);
                  System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");
            } catch (ConnectException e) {
                System.out.println("获取OpenOffice连接失败...");
                e.printStackTrace();
            }
            finally{
                connection.disconnect();
            }
          } catch (Exception e) {
              System.out.println("转换失败:"+filePath);
              e.printStackTrace();
          }
      }
    private static DocumentConverter getConverter(String connectIp, OpenOfficeConnection connection) {
        DocumentConverter converter = "localhost".equals(connectIp) || "127.0.0.1".equals(connectIp)
                || "0:0:0:0:0:0:0:1".equals(connectIp) ? new OpenOfficeDocumentConverter(connection)
                        : new StreamOpenOfficeDocumentConverter(connection);
        return converter;
    }

}

测试:

package openoffice;

import aspose.AsposeUtil;

/**
 * @author sonyan
 * @version 2019年9月25日 下午1:12:21
 * @desc
 */
public class Test {

    private static void testWord(String path_word, String pafpath) throws Exception {
        String word1 = path_word + "01正方数字.docx";
        String word2 = path_word + "02正方数字.docx";
        String word3 = path_word + "03正方数字.doc";
        String word4 = path_word + "04正方数字.doc";
        String word5 = path_word + "05正方数字.docx";
        String word6 = path_word + "06正方数字.doc";

        OpenOfficeUtils.toPdf(word1, pafpath + "Open-word-01测试.pdf");
        OpenOfficeUtils.toPdf(word2, pafpath + "Open-word-02测试.pdf");
        OpenOfficeUtils.toPdf(word3, pafpath + "Open-word-03测试.pdf");
        OpenOfficeUtils.toPdf(word4, pafpath + "Open-word-04测试.pdf");
        OpenOfficeUtils.toPdf(word5, pafpath + "Open-word-05测试.pdf");
        OpenOfficeUtils.toPdf(word6, pafpath + "Open-word-06测试.pdf");

    }

    private static void testWord2(String path_word, String pafpath) throws Exception {
        String word1 = path_word + "01.docx";
        String word2 = path_word + "02.docx";
        String word3 = path_word + "03.doc";
        String word4 = path_word + "04.doc";
        String word5 = path_word + "05.docx";
        String word6 = path_word + "06.doc";

        OpenOfficeUtils.toPdf(word1, pafpath + "Open-word-01.pdf");
        OpenOfficeUtils.toPdf(word2, pafpath + "Open-word-02.pdf");
        OpenOfficeUtils.toPdf(word3, pafpath + "Open-word-03.pdf");
        OpenOfficeUtils.toPdf(word4, pafpath + "Open-word-04.pdf");
        OpenOfficeUtils.toPdf(word5, pafpath + "Open-word-05.pdf");
        OpenOfficeUtils.toPdf(word6, pafpath + "Open-word-06.pdf");

    }

    private static void testTxt(String path_word, String pafpath) throws Exception {
        String txt1 = path_word + "01jvm.txt";
        String txt2 = path_word + "02jvm.txt";
        String txt3 = path_word + "03jvm.txt";

        OpenOfficeUtils.toPdf(txt1, pafpath + "Open-txt-01测试.pdf");
        OpenOfficeUtils.toPdf(txt2, pafpath + "Open-txt-02测试.pdf");
        OpenOfficeUtils.toPdf(txt3, pafpath + "Open-txt-03测试.pdf");
    }

    private static void testTxt2(String path_word, String pafpath) throws Exception {
        String txt1 = path_word + "01jvm.txt";
        String txt2 = path_word + "02jvm.txt";
        String txt3 = path_word + "03jvm.txt";

        OpenOfficeUtils.toPdf(txt1, pafpath + "Open-txt-01.pdf");
        OpenOfficeUtils.toPdf(txt2, pafpath + "Open-txt-02.pdf");
        OpenOfficeUtils.toPdf(txt3, pafpath + "Open-txt-03.pdf");
    }

    private static void testExcel(String path_word, String pafpath) throws Exception {
        String txt1 = path_word + "01部门开发任务管理.xlsx";
        String txt2 = path_word + "02部门开发任务管理.xlsx";
        String txt3 = path_word + "03部门开发任务管理.xlsx";

        OpenOfficeUtils.toPdf(txt1, pafpath + "Open-excel-01测试.pdf");
        OpenOfficeUtils.toPdf(txt2, pafpath + "Open-excel-02测试.pdf");
        OpenOfficeUtils.toPdf(txt3, pafpath + "Open-excel-03测试.pdf");
    }

    private static void testExcel2(String path_word, String pafpath) throws Exception {
        String txt1 = path_word + "01.xlsx";
        String txt2 = path_word + "02.xlsx";
        String txt3 = path_word + "03.xlsx";

        OpenOfficeUtils.toPdf(txt1, pafpath + "Open-excel-01.pdf");
        OpenOfficeUtils.toPdf(txt2, pafpath + "Open-excel-02.pdf");
        OpenOfficeUtils.toPdf(txt3, pafpath + "Open-excel-03.pdf");
    }

    private static void testPPt(String path_ppt, String pafpath) throws Exception {
        String txt1 = path_ppt + "01jquery培训.pptx";
        String txt2 = path_ppt + "02jquery培训.pptx";
        String txt3 = path_ppt + "03jquery培训.ppt";

        OpenOfficeUtils.toPdf(txt1, pafpath + "Open-ppt-01测试.pdf");
        OpenOfficeUtils.toPdf(txt2, pafpath + "Open-ppt-02测试.pdf");
        OpenOfficeUtils.toPdf(txt3, pafpath + "Open-ppt-03测试.pdf");
    }

    private static void testPPt2(String path_ppt, String pafpath) throws Exception {
        String txt1 = path_ppt + "01jquery.pptx";
        String txt2 = path_ppt + "02jquery.pptx";
        String txt3 = path_ppt + "03jquery培训.ppt";

        OpenOfficeUtils.toPdf(txt1, pafpath + "Open-ppt-01.pdf");
        OpenOfficeUtils.toPdf(txt2, pafpath + "Open-ppt-02.pdf");
        OpenOfficeUtils.toPdf(txt3, pafpath + "Open-ppt-03.pdf");
    }

    public static void LinuxTest() throws Exception {
        String path_word = "/software/songyan/hah/01word/";
        String path_txt = "/software/songyan/hah/02txt/";
        String path_excel = "/software/songyan/hah/03excel/";
        String path_ppt = "/software/songyan/hah/04ppt/";
        String pafpath = "/software/songyan/hah/pdf/";

        System.out.println("************************");
        testTxt(path_txt, pafpath);
        System.out.println("************************");
        testExcel(path_excel, pafpath);
        System.out.println("************************");
        testPPt(path_ppt, pafpath);
        System.out.println("************************");
        testWord(path_word, pafpath);
    }

    public static void LinuxTest2() throws Exception {
        String path_word = "/software/songyan/hah/01word/";
        String path_txt = "/software/songyan/hah/02txt/";
        String path_excel = "/software/songyan/hah/03excel/";
        String path_ppt = "/software/songyan/hah/04ppt/";
        String pafpath = "/software/songyan/hah/pdf/";

        System.out.println("************************");
        testTxt2(path_txt, pafpath);
        System.out.println("************************");
        testExcel2(path_excel, pafpath);
        System.out.println("************************");
        testPPt2(path_ppt, pafpath);
        System.out.println("************************");
        testWord2(path_word, pafpath);
    }

    public static void winTest() throws Exception {
        String path_word = "C:/Users/Administrator.DESKTOP-QN9A3AA/Desktop/office/测试文档/转换前文档/01word/";
        String path_txt = "C:/Users/Administrator.DESKTOP-QN9A3AA/Desktop/office/测试文档/转换前文档/02txt/";
        String path_excel = "C:/Users/Administrator.DESKTOP-QN9A3AA/Desktop/office/测试文档/转换前文档/03excel/";
        String path_ppt = "C:/Users/Administrator.DESKTOP-QN9A3AA/Desktop/office/测试文档/转换前文档/04ppt/";
        String pafpath = "C:/Users/Administrator.DESKTOP-QN9A3AA/Desktop/office/测试文档/pdf/";

        System.out.println("************************");
        testWord(path_word, pafpath);
        System.out.println("************************");
        testTxt(path_txt, pafpath);
        System.out.println("************************");
        testExcel(path_excel, pafpath);
        System.out.println("************************");
        testPPt(path_ppt, pafpath);
    }
    
    public static void main(String[] args) throws Exception {
        winTest();
    }
}
View Code

 

 (2)首次使用遇到的坑

1)看下面的代码,需要提供的openoffice服务器的安装地址以及端口号,需要注ip(有的需要写内网的ip,有的需要写成127.0.0.1,也有的需要写成localhost),具体写成什么形式根据电脑中一个文件的配置,具体的自行百度

2)开启openoffice服务,如果在转换的过程中强制性杀进程,在连接会出现连接拒绝的问题(我在windows上启动的openoffice,使用linux连接时,有一次连接成功,可以正常的转换,但是当时强制性的杀掉了进程,之后再重启,重装都会连接失败,而且linux尝试连接后,本机再去请求连接也会被拒绝,具体的原因还没找到,这种方式被很多公司正式的使用,应该有解决方案),最后是在linux服务器安装了openoffice,在linux也连接自己的服务完成的测试

三、第三种方式是jacob:这种方式使用起来很方便,把dll文件放到jre的bin目录,引入jar包就可以使用,但是它只支持windows系统,而且转换的速度相对aspose方式来讲要慢一些,对于在部署在windows上,对转换速度要求不高的可以使用这种方式。

(1)代码:

1.下载jacob.jar,将jacob.jar导入程序中,把对应的jcob.dll拷贝到system32/SysWOW64目录下,同时也拷贝到对应的jre的bin目录下。

2.编写转换代码

package jacob;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

public class JacobUtil {
    //计时
    public static void trans(String filePath, String pdfPath,String type) {
          try {
              long old = System.currentTimeMillis();
              System.out.println("jav-转换开始:" + filePath);
              toPdf(filePath,pdfPath, type);
              System.out.println("完成:" + pdfPath);
              long now = System.currentTimeMillis();
              System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");
          } catch (Exception e) {
              System.out.println("转换失败:" + filePath);
              e.printStackTrace();
          }
      }

    //转换
    private static void toPdf(String filePath, String pdfPath,String type) {
        if("word".equals(type)){
            word2PDF(filePath,pdfPath);
        }else if("excel".equals(type)){
            excel2PDF(filePath,pdfPath);
        }else if("ppt".equals(type)){
            ppt2PDF(filePath,pdfPath);
        }
    }
    
    private static void word2PDF(String inputFile, String pdfFile) {
        ActiveXComponent app = new ActiveXComponent("Word.Application");
        try {
            app.setProperty("Visible", false);
            Dispatch docs = app.getProperty("Documents").toDispatch();
            Dispatch doc = Dispatch.call(docs, "Open", new Object[]{inputFile, false, true}).toDispatch();
            Dispatch.call(doc, "ExportAsFixedFormat", new Object[]{pdfFile, 17});
            Dispatch.call(doc, "Close", new Object[]{false});
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("转换出错:"+pdfFile);
        }finally {
            app.invoke("Quit");
        }
    }

    private static void excel2PDF(String inputFile, String pdfFile) {
        ComThread.InitSTA(true);
        ActiveXComponent app = new ActiveXComponent("Excel.Application");
        try {
            app.setProperty("Visible", false);
            app.setProperty("AutomationSecurity", new Variant(3));
            Dispatch excels = app.getProperty("Workbooks").toDispatch();
            Dispatch excel = Dispatch.invoke(excels, "Open", 1, new Object[]{inputFile, new Variant(false), new Variant(false)}, new int[9]).toDispatch();
            Dispatch.invoke(excel, "ExportAsFixedFormat", 1, new Object[]{new Variant(0), pdfFile, new Variant(0)}, new int[1]);
            Dispatch.call(excel, "Close", new Object[]{false});
            if (app != null) {
                app.invoke("Quit", new Variant[0]);
                app = null;
            }
            ComThread.Release();
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("转换出错:"+pdfFile);
        }finally {
            app.invoke("Quit");
        }
    }

    private static void ppt2PDF(String inputFile, String pdfFile) {
        ActiveXComponent app = new ActiveXComponent("PowerPoint.Application");
        try {
            Dispatch ppts = app.getProperty("Presentations").toDispatch();
            Dispatch ppt = Dispatch.call(ppts, "Open", new Object[]{inputFile, true, true, false}).toDispatch();
            Dispatch.call(ppt, "SaveAs", new Object[]{pdfFile, 32});
            Dispatch.call(ppt, "Close");
            app.invoke("Quit");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("转换出错:"+inputFile);
        }finally {
            app.invoke("Quit");
        }
    }
    
   
  
}

测试:

package jacob;

/**
 * @author sonyan
 * @version 2019年9月25日 下午1:12:21
 * @desc
 */
public class Test {

    private static void testWord(String path_word, String pdfPath) throws Exception {
        String word1 = path_word + "01正方数字.docx";
        String word2 = path_word + "02正方数字.docx";
        String word3 = path_word + "03正方数字.doc";
        String word4 = path_word + "04正方数字.doc";
        String word5 = path_word + "05正方数字.docx";
        String word6 = path_word + "06正方数字.doc";

        JacobUtil.trans(word1, pdfPath + "jac-word-01测试.pdf", "word");
        JacobUtil.trans(word2, pdfPath + "jac-word-02测试.pdf", "word");
        JacobUtil.trans(word3, pdfPath + "jac-word-03测试.pdf", "word");
        JacobUtil.trans(word4, pdfPath + "jac-word-04测试.pdf", "word");
        JacobUtil.trans(word5, pdfPath + "jac-word-05测试.pdf", "word");
        JacobUtil.trans(word6, pdfPath + "jac-word-06测试.pdf", "word");

    }

    private static void testWord1(String path_word, String pdfPath) throws Exception {
        String word1 = path_word + "01.docx";
        String word2 = path_word + "02.docx";
        String word3 = path_word + "03.doc";
        String word4 = path_word + "04.doc";
        String word5 = path_word + "05.docx";
        String word6 = path_word + "06.doc";

        JacobUtil.trans(word1, pdfPath + "jac-word-01.pdf", "word");
        JacobUtil.trans(word2, pdfPath + "jac-word-02.pdf", "word");
        JacobUtil.trans(word3, pdfPath + "jac-word-03.pdf", "word");
        JacobUtil.trans(word4, pdfPath + "jac-word-04.pdf", "word");
        JacobUtil.trans(word5, pdfPath + "jac-word-05.pdf", "word");
        JacobUtil.trans(word6, pdfPath + "jac-word-06.pdf", "word");

    }

    private static void testTxt(String path_txt, String pdfPath) throws Exception {
        String txt1 = path_txt + "01jvm.txt";
        String txt2 = path_txt + "02jvm.txt";
        String txt3 = path_txt + "03jvm.txt";

        JacobUtil.trans(txt1, pdfPath + "jac-txt-01测试.pdf", "word");
        JacobUtil.trans(txt2, pdfPath + "jac-txt-02测试.pdf", "word");
        JacobUtil.trans(txt3, pdfPath + "jac-txt-03测试.pdf", "word");
    }

    private static void testTxt1(String path_txt, String pdfPath) throws Exception {
        String txt1 = path_txt + "01jvm.txt";
        String txt2 = path_txt + "02jvm.txt";
        String txt3 = path_txt + "03jvm.txt";

        JacobUtil.trans(txt1, pdfPath + "jac-txt-01.pdf", "word");
        JacobUtil.trans(txt2, pdfPath + "jac-txt-02.pdf", "word");
        JacobUtil.trans(txt3, pdfPath + "jac-txt-03.pdf", "word");
    }

    private static void testExcel(String path_excel, String pdfPath) throws Exception {

        String txt1 = path_excel + "01部门开发任务管理.xlsx";
        String txt2 = path_excel + "02部门开发任务管理.xlsx";
        String txt3 = path_excel + "03部门开发任务管理.xlsx";

        JacobUtil.trans(txt1, pdfPath + "jac-excel-01测试.pdf", "excel");
        JacobUtil.trans(txt2, pdfPath + "jac-excel-02测试.pdf", "excel");
        JacobUtil.trans(txt3, pdfPath + "jac-excel-03测试.pdf", "excel");
    }

    private static void testExcel1(String path_excel, String pdfPath) throws Exception {

        String txt1 = path_excel + "01.xlsx";
        String txt2 = path_excel + "02.xlsx";
        String txt3 = path_excel + "03.xlsx";

        JacobUtil.trans(txt1, pdfPath + "jac-excel-01.pdf", "excel");
        JacobUtil.trans(txt2, pdfPath + "jac-excel-02.pdf", "excel");
        JacobUtil.trans(txt3, pdfPath + "jac-excel-03.pdf", "excel");
    }

    private static void testPPt(String path_ppt, String pdfPath) throws Exception {

        String txt1 = path_ppt + "01jquery培训.pptx";
        String txt2 = path_ppt + "02jquery培训.pptx";
        String txt3 = path_ppt + "03jquery培训.ppt";

        JacobUtil.trans(txt1, pdfPath + "jac-ppt-01测试.pdf", "ppt");
        JacobUtil.trans(txt2, pdfPath + "jac-ppt-02测试.pdf", "ppt");
        JacobUtil.trans(txt3, pdfPath + "jac-ppt-03测试.pdf", "ppt");
    }

    private static void testPPt1(String path_ppt, String pdfPath) throws Exception {
        String txt1 = path_ppt + "01jquery.pptx";
        String txt2 = path_ppt + "02jquery.pptx";
        String txt3 = path_ppt + "03jquery.ppt";

        JacobUtil.trans(txt1, pdfPath + "jac-ppt-01.pdf", "ppt");
        JacobUtil.trans(txt2, pdfPath + "jac-ppt-02.pdf", "ppt");
        JacobUtil.trans(txt3, pdfPath + "jac-ppt-03.pdf", "ppt");
    }
    
    public static void winTest() throws Exception {
        String path_word = "C:/Users/Administrator.DESKTOP-QN9A3AA/Desktop/office/测试文档/转换前文档/01word/";
        String path_txt = "C:/Users/Administrator.DESKTOP-QN9A3AA/Desktop/office/测试文档/转换前文档/02txt/";
        String path_excel = "C:/Users/Administrator.DESKTOP-QN9A3AA/Desktop/office/测试文档/转换前文档/03excel/";
        String path_ppt = "C:/Users/Administrator.DESKTOP-QN9A3AA/Desktop/office/测试文档/转换前文档/04ppt/";
        String pdfPath = "C:/Users/Administrator.DESKTOP-QN9A3AA/Desktop/office/测试文档/pdf/";
        System.out.println("word测试");
        testWord(path_word, pdfPath);
        System.out.println("txt测试");
        testTxt(path_txt, pdfPath);
        System.out.println("ppt测试");
        testPPt(path_ppt, pdfPath);
        System.out.println("excel测试");
        testExcel(path_excel, pdfPath);
    }

    public static void LinuxTest() throws Exception {
        String path_word = "/software/songyan/hah/01word/";
        String path_txt = "/software/songyan/hah/02txt/";
        String path_excel = "/software/songyan/hah/03excel/";
        String path_ppt = "/software/songyan/hah/04ppt/";
        String pdfPath = "/software/songyan/hah/pdf/";
        
        System.out.println("word测试");
        testWord(path_word, pdfPath);
        System.out.println("txt测试");
        testTxt(path_txt, pdfPath);
        System.out.println("ppt测试");
        testPPt(path_ppt, pdfPath);
        System.out.println("excel测试");
        testExcel(path_excel, pdfPath);
    }

    public static void LinuxTest2() throws Exception {
        String path_word = "/software/songyan/hah/01word/";
        String path_txt = "/software/songyan/hah/02txt/";
        String path_excel = "/software/songyan/hah/03excel/";
        String path_ppt = "/software/songyan/hah/04ppt/";
        String pdfPath = "/software/songyan/hah/pdf/";
        
        System.out.println("word测试");
        testWord1(path_word, pdfPath);
        System.out.println("txt测试");
        testTxt1(path_txt, pdfPath);
        System.out.println("ppt测试");
        testPPt1(path_ppt, pdfPath);
        System.out.println("excel测试");
        testExcel1(path_excel, pdfPath);
    }
    
    public static void main(String[] args) throws Exception {
        winTest();
    }
    
}
View Code

 

四、测试结果

 五、项目,jar包,测试材料

链接:https://pan.baidu.com/s/17-dyFq7PM9wE9rMVHVawBw
提取码:0oq5 

分类:

技术点:

相关文章:

  • 2021-12-19
  • 2021-09-28
  • 2021-10-12
  • 2021-09-27
  • 2021-08-03
  • 2021-11-24
  • 2021-11-01
  • 2021-12-20
猜你喜欢
  • 2021-12-01
  • 2021-12-19
  • 2021-12-10
  • 2021-09-11
  • 2022-01-02
  • 2021-12-19
  • 2021-11-06
相关资源
相似解决方案