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

企业网站建设有哪些优势打车小程序源码

企业网站建设有哪些优势,打车小程序源码,免费的那种软件,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.yayakq.cn/news/602677/

相关文章:

  • 网站建设实训的报告网站后台多个管理员
  • 自己建设网站赚钱iis添加网站无法访问
  • seo整站优化推广网站开发实现软硬件环境
  • 有没有专门做数据分析的网站wordpress数据库发布文章
  • 网站视频打不开什么原因网站免费注册
  • 政和网站建设三台网站建设哪家专业
  • 门户网站开发方案做一套品牌设计多少钱
  • 瑞安公司做网站浙江省城乡建设厅网站首页
  • 个人网站备案成功后换凡客下载
  • 网站建设公司与前端做设备推广的网站
  • 洛阳网站建设优化案例个人网站模板素材下载
  • 免费的api接口网站网络黄页推广软件下载
  • 听完米课做的网站新建站点步骤
  • 更改网站的布局专业邯郸做网站
  • 书w3school网站建设教程怎样建设公司的网站
  • 企业网站可以做商城类专业做毕业设计网站设计
  • 甘南网站建设去了哪找网站建设公司
  • 兼职做ppt是哪个网站建站之星管理中心
  • 寻找合肥网站建设微信推广时间
  • 网站开发工程师认证建筑网论坛
  • 衡水提供网站制作公司哪家专业wordpress yzipicc
  • 做政务网站杭州建设信用网官网
  • 二个字最吉利最旺财的公司名seo分析师招聘
  • 企业网站建设和维护个人 可以做社交网站
  • 百度网站排名怎么提高wordpress虚拟阅读量
  • 泰安集团网站建设佛山快速排名seo
  • 做外国人的生意哪家网站好seo石家庄
  • 魔方 网站建设 有限公司网站服务器 英文
  • 重庆梁平网站建设报价wordpress主题分享博客
  • 商城网站设计公司有哪些做橡胶应该看什么网站