当前位置: 首页 > news >正文

网站管理端怎么做地推拉新app推广平台

网站管理端怎么做,地推拉新app推广平台,用wordpress建立的网站吗,东方头条网站源码一、多余的话 java实现word转pdf可用的jar包不多,很多都是收费的。最近发现com.documents4j挺好用的,它支持在本机转换,也支持远程服务转换。但它依赖于微软的office。电脑需要安装office才能转换。鉴于没在linux中使用office,本…

一、多余的话

java实现word转pdf可用的jar包不多,很多都是收费的。最近发现com.documents4j挺好用的,它支持在本机转换,也支持远程服务转换。但它依赖于微软的office。电脑需要安装office才能转换。鉴于没在linux中使用office,本文转换在windows中进行。

用途:主要是对word文件转换成pdf后,提供在线预览服务。也可以用于合同生成等。

二、前提条件

windows服务器或电脑需安装office软件。

三、代码实现

添加依赖:

        <dependency><groupId>com.documents4j</groupId><artifactId>documents4j-local</artifactId><version>1.1.6</version></dependency><dependency><groupId>com.documents4j</groupId><artifactId>documents4j-transformer-msoffice-word</artifactId><version>1.1.6</version></dependency>

转换代码类:WordToPdfUtil.java

package com.lan.fts.util;import com.documents4j.api.*;
import com.documents4j.job.LocalConverter;import java.io.*;
import java.util.concurrent.Future;public class WordToPdfUtil {private IConverter getConverter(){return LocalConverter.builder().build();}private void releaseConverter(IConverter converter){converter.shutDown();}public boolean wordToPdf(String fromFilePath, String pdfFilePath){boolean result = false;File inputFile = new File(fromFilePath);File outputFile = new File(pdfFilePath);InputStream inputStream=null;OutputStream outputStream = null;IConverter converter = getConverter();try {inputStream = new FileInputStream(inputFile);outputStream = new FileOutputStream(outputFile);String wordFilePath_low=fromFilePath.toLowerCase();if (wordFilePath_low.endsWith(".docx")) {Future<Boolean> schedule = converter.convert(inputStream, true).as(DocumentType.DOCX).to(outputStream, true).as(DocumentType.PDF).schedule();result = waitsShedule(schedule, 180000);}else if(wordFilePath_low.endsWith(".doc")){Future<Boolean> schedule = converter.convert(inputStream, true).as(DocumentType.DOC).to(outputStream, true).as(DocumentType.PDF).schedule();result = waitsShedule(schedule, 180000);}else if(wordFilePath_low.endsWith(".txt")){Future<Boolean> schedule = converter.convert(inputStream, true).as(DocumentType.TEXT).to(outputStream, true).as(DocumentType.PDF).schedule();result = waitsShedule(schedule, 180000);}} catch (FileNotFoundException e) {e.printStackTrace();} finally {try {if(outputStream!=null)outputStream.close();} catch (IOException e) {};try {if(inputStream!=null)inputStream.close();} catch (IOException e) {};releaseConverter(converter);}return result;}private boolean waitsShedule(Future<Boolean> schedule, int timeout){int time=0;while (!schedule.isDone()){MyThread.sleep(500);time+=500;if(time>timeout){schedule.cancel(true);return false;}}return true;}public static void main(String[] args) {//	new WordToPdfUtil().wordToPdf("D:\\data\\out\\ffec88b6ee26397bf99834acb059f7b0.docx", "D:\\data\\out\\ffec88b6ee26397bf99834acb059f7b0.docx.pdf");}}

说明:waitsShedule,是等待转换完成。如果超时,将取消转换任务

四、运行验证

	public static void main(String[] args) {new WordToPdfUtil().wordToPdf("D:\\data\\out\\lanhezhong文件转换.docx", "D:\\data\\out\\lanhezhong文件转换.docx.pdf");}

运行结果:

***********************************************************************************************
author:蓝何忠
email:lanhezhong@163.com
***********************************************************************************************

http://www.shuangfujiaoyu.com/news/47740.html

相关文章:

  • 乐陵是哪个省哪个市的东莞网站建设优化
  • 数据中心idc机房湖南seo推广
  • 怎么用word做网站漳州网络推广
  • 阿里云 网站建设百度快照怎么使用
  • 广东做陶瓷的网站哈尔滨优化调整人员流动管理
  • 陕西省住房和城乡建设厅执业资格注册中心网站seo首页网站
  • 51做图片的网站长沙网络推广外包
  • 做网站推广的是什么职位无锡网站seo
  • 如何建设管理好法院网站seo关键词优化软件怎么样
  • 哪里有做网站排名优化线上推广
  • 保险公司网站建设方案衡阳网站优化公司
  • 乌鲁木齐做网站公司哪家好百度宣传推广费用
  • 一个空间怎么放2个网站搜索引擎优化结果
  • 网站建设一般好久到期国外域名注册平台
  • 商学院网站建设建议外链推广网站
  • 建设论坛网站自学seo搜索引擎优化是做什么的
  • 石景山区建设委员会网站网络推广软文范文
  • 帝国cms网站地图生成中国国家人事人才培训网证书查询
  • 家政的网站怎么做免费网站安全软件下载
  • 政府网站信息建设工作广州外包网络推广公司
  • 浙江做网站多少钱关键词优化哪家强
  • 网站服务器自己做seo优化啥意思
  • 做园区门户网站的需求分析制作网页模板
  • 行业前10的网站建设公汕头seo网站推广
  • 建筑人才网 中高端招聘网站百度开发者平台
  • 黄冈论坛交友重庆seo主管
  • 重庆百度网站快速排名手机制作网页
  • 做英语题的网站苏州关键词优化软件
  • 沈阳做网站大约要多少钱外贸网站推广
  • 那些因素会影响网站的排名位置网络营销活动策划方案