国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

執法文書打印的實現(三)(word→png的實現)

2019-11-14 22:47:34
字體:
來源:轉載
供稿:網友
執法文書打印的實現(三)(Word→png的實現)

執法文書打印的實現(word^png的實現)

寫這篇博客,心里很忐忑和沉重。由于知識結構等多方面的原因,redhat上啟動openoffice環境浪費了許多時間和精力。一些驗證通過的命令、方法等稍微改變就慌手慌腳卡了進度,如果有得選擇,我應該不會用openoffice實現。畢竟我的興趣和預職業方向是jee和前端,做這些工作有點偏了,實在提不起來勁頭。

這部分的代碼都是網上抄的,大部分都一樣,算是固定格式,沒有多少個人發揮的余地。Openoffice實現word to pdf,icepdf實現pdf to png。Icepdf是收費軟件,使用有風險,轉換出的圖片效果確實比較驚艷,也可以自由調整精度。

Openoffice的安裝與服務啟動

下載安裝包:http://www.openoffice.org/download/index.html

在redhat下解壓安裝文件:tar -zxvf 壓縮文件名.tar.gz 解壓后的文件只能放在當前目錄

安裝依賴項:cd zh-CN/RPMS/ rpm –ivh *.rpm

安裝桌面:cd desktop-integration/ rpm -ivh openoffice4.1.1-redhat-menus-4.1.1-9775.noarch.rpm

進入安裝目錄:cd /opt/openoffice4/PRogram/

啟動服務:soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" –nofirststartwizard & (注意:這里有個坑,命令最后的"&"符最好添加,上星期kill 掉soffice.bin進程后一直啟動不起來,原因就是沒有添加"&",不知道什么原因,希望知道的園友能解惑)

查看監聽是否創建成功:netstat -apn|grep 8100

卸載:rpm -e `rpm -qa |grep openoffice` `rpm -qa |grep ooobasis`

具體word→png:java代碼

  

/**     *      * @param sourceName  doc文件名     * @param zoom 圖片清晰度       * @return      * @throws Exception     */    public  String[] opt2png(String sourceName,float zoom) throws Exception {        //圖片磁盤絕對路徑:可以作為方法的返回值        String imgFilePaths [];                 //每次生成一個隨機的pdf,每天凌晨啟動一個自動任務清空 pdfFile目錄        File inputFile = new File(wordFilePath+File.separator+sourceName);          if (!inputFile.exists()) {              //return -1;// 找不到源文件, 則返回-1            System.out.println("找不到word文件"+wordFilePath+File.separator+sourceName);            return null;        }        //生成隨機的pdf文件        String pdfname=UUID.randomUUID().toString();        pdfFilePath=pdfFilePath+File.separator+pdfname+".pdf";        File outputFile = new File(pdfFilePath);          if (!outputFile.getParentFile().exists()) {              outputFile.getParentFile().mkdirs();          }                //啟動服務:不是很好用,需要手動啟動        String command =officeHome+ "program"+File.separator+"soffice -headless -accept=/"socket,host=127.0.0.1,port=8100;urp;/"";        Process pro=null;        try {            pro = Runtime.getRuntime().exec(command);        } catch (IOException e) {            e.printStackTrace();        }        //建立連接        OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);        try {            connection.connect();        } catch (Exception e) {            // TODO 自動生成的 catch 塊            e.printStackTrace();        }                 DocumentConverter converter = new OpenOfficeDocumentConverter(connection);          try {            converter.convert(inputFile, outputFile);  //這個方法的執行不可調試        } catch (Exception e) {            // TODO 自動生成的 catch 塊            e.printStackTrace();        }finally{            // close the connection              connection.disconnect();              // 關閉OpenOffice服務的進程              pro.destroy();             //生成pdf成功        }                                        //icepdf  work        Document document = null;        float rotation = 0f;        document = new Document();        document.setFile(pdfFilePath);         //獲得文檔的頁數        int pageNum=document.getNumberOfPages();                imgFilePaths=new String[pageNum];        String imgFileName;        for (int i = 0; i < pageNum; i++) {            //下面這行的代碼執行不可調試            BufferedImage img = (BufferedImage) document.getPageImage(i,GraphicsRenderingHints.SCREEN, Page.BOUNDARY_CROPBOX, rotation,zoom);            Iterator iter = ImageIO.getImageWritersBySuffix("png");            ImageWriter writer = (ImageWriter) iter.next();            imgFileName=UUID.randomUUID().toString();            File outFile = new File(pngFilePath+File.separator+imgFileName+".png");            FileOutputStream out = new FileOutputStream(outFile);            ImageOutputStream outImage = ImageIO.createImageOutputStream(out);            writer.setOutput(outImage);            writer.write(new IIOImage(img, null, null));            imgFilePaths[i]=pngFilePath+File.separator+imgFileName+".png";        }        return imgFilePaths;    }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 噶尔县| 阿鲁科尔沁旗| 南澳县| 莱州市| 元江| 铅山县| 泸定县| 永嘉县| 冕宁县| 新竹市| 兰坪| 德令哈市| 涿鹿县| 玛沁县| 瑞金市| 克什克腾旗| 称多县| 九龙城区| 大足县| 达拉特旗| 夹江县| 裕民县| 夏河县| 准格尔旗| 贞丰县| 宁强县| 五家渠市| 通海县| 金门县| 开江县| 大理市| 荥阳市| 石楼县| 岳池县| 正镶白旗| 东兴市| 张掖市| 锡林浩特市| 博罗县| 荔浦县| 建宁县|