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

浙江建设信息网青岛seo公司

浙江建设信息网,青岛seo公司,武汉网页设计班培训,南昌app定制前言 java实现word文档转PDF&#xff0c;PDF转word 解决只能转换4页问题 解决每页头部存在水印问题 实现 引入依赖 <dependency><groupId>com.documents4j</groupId><artifactId>documents4j-local</artifactId><version>1.0.3</ve…

前言

java实现word文档转PDF,PDF转word
解决只能转换4页问题
解决每页头部存在水印问题

实现

引入依赖

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

破解的jar包
链接: https://pan.baidu.com/s/1MO8OBuf4FQ937R9KDtofPQ 提取码: 4tsn

package com.common.util;import com.aspose.pdf.Document;
import com.aspose.pdf.SaveFormat;
import com.documents4j.api.DocumentType;
import com.documents4j.api.IConverter;
import com.documents4j.job.LocalConverter;import java.io.*;/*** PDF转换工具类* @author yyq*/
public class PdfUtil {public static void main(String[] args) {//pdfToObj("C:\\Users\\Administrator\\Desktop\\测试.pdf", "docx");String filePath = "C:\\Users\\Administrator\\Desktop\\测试.docx";String outFilePath = "C:\\Users\\Administrator\\Desktop\\测试.pdf";objToPdf(filePath, outFilePath, "docx");}/*** PDF 转 doc、Excel、xml* @param pdfPath 需要转换的pdf路径* @param suffix 文件后缀*/public static void pdfToObj(String pdfPath, String suffix) {long old = System.currentTimeMillis();FileOutputStream os = null;try {// 新建一个word文档String wordPath = pdfPath.substring(0, pdfPath.lastIndexOf(".")) + "." + suffix;os = new FileOutputStream(wordPath);// doc是将要被转化的word文档Document doc = new Document(pdfPath);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换if(suffix.equals("doc")){doc.save(os, SaveFormat.Doc);}else if(suffix.equals("docx")){doc.save(os, SaveFormat.DocX);}else if(suffix.equals("xls") || suffix.equals("xlsx")){doc.save(os, SaveFormat.Excel);}else if(suffix.equals("html")){doc.save(os, SaveFormat.Html);}else if(suffix.equals("xml")){doc.save(os, SaveFormat.Xml);}os.close();// 转化耗时long now = System.currentTimeMillis();long useTime = ((now - old) / 1000);System.out.println("Pdf 转 Word 共耗时:" + useTime + "秒");} catch (Exception e) {System.out.println("Pdf 转 Word 失败...");e.printStackTrace();}finally {try {os.close();} catch (IOException e) {e.printStackTrace();}}}/*** txt、doc、Excel、xml 转 PDF* @param oidPath 需要转的文件路径* @param newPath 转成的PDF文件路径*/public static void objToPdf(String oidPath, String newPath, String suffix){InputStream inputStream = null;OutputStream outputStream = null;IConverter converter = null;try {// 源文件地址File oidFile = new File(oidPath);// 导出文件地址File newFile = new File(newPath);// 文件读取inputStream = new FileInputStream(oidFile);outputStream = new FileOutputStream(newFile);// 开始转换converter = LocalConverter.builder().build();boolean flag = false;if(suffix.equals("doc")){flag = converter.convert(inputStream).as(DocumentType.DOC).to(outputStream).as(DocumentType.PDF).execute();}else if(suffix.equals("docx")){flag = converter.convert(inputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();}else if(suffix.equals("txt")){flag = converter.convert(inputStream).as(DocumentType.TEXT).to(outputStream).as(DocumentType.PDF).execute();}else if(suffix.equals("xls")){flag = converter.convert(inputStream).as(DocumentType.XLS).to(outputStream).as(DocumentType.PDF).execute();}else if(suffix.equals("xlsx")){flag = converter.convert(inputStream).as(DocumentType.XLSX).to(outputStream).as(DocumentType.PDF).execute();}else if(suffix.equals("html")){flag = converter.convert(inputStream).as(DocumentType.MHTML).to(outputStream).as(DocumentType.PDF).execute();}else if(suffix.equals("xml")){flag = converter.convert(inputStream).as(DocumentType.XML).to(outputStream).as(DocumentType.PDF).execute();}if (flag) {converter.shutDown();}inputStream.close();outputStream.close();System.out.println("转换成功");} catch (Exception e) {converter.shutDown();e.printStackTrace();System.out.println("转换失败");}finally {try {inputStream.close();outputStream.close();} catch (IOException e) {e.printStackTrace();}}}}

源码路径:https://download.csdn.net/download/weixin_43992507/88215577

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

相关文章:

  • 洛阳高端网站建设百度竞价项目
  • 中国建设招标工程网站广州营销网站建设靠谱
  • 设计一个企业网站大概多少钱西安做seo的公司
  • 中山精品网站建设新闻seo博客网站
  • 晋城网站seo搜索引擎竞价排名
  • 网站后台做1个多少钱谷歌浏览器下载安装2022最新版
  • 企业展示型网站 建站系统谷歌搜索引擎免费入口 台湾
  • 网站开发中网页之间的连接形式南京百度推广优化
  • 服务器色情网站专用北京网站建设运营
  • 做优化网站是什么意思上海最新发布最新
  • 网站关键词多少个字数 站长网注册域名后如何建立网站
  • 漳州建网站深圳知名网络优化公司
  • nodejs 做视频网站重庆seo全面优化
  • 建设银行兰州分行网站百度网站首页
  • 百度站长平台h5网站如何开发软件app
  • 门户网站申请百度百家号注册
  • 大学生实训网站建设心得北京网站优化服务
  • 个人介绍网页设计作品seo推广策划
  • 自己用模板做网站天天seo百度点击器
  • 小程序定义电商seo与sem是什么
  • 做youtube视频网站青岛网站制作公司
  • 怎么做属于自己的网站网络营销优化培训
  • 带做网站价位seo推广有哪些方式
  • 做西点网站苏州网站
  • 青岛seo百科北京百度推广排名优化
  • 网站建设公司业务人员岗位职责实体店营销方案
  • 北京服饰电商网站建设广州顶正餐饮培训学校
  • 备案要关闭网站吗爱网站
  • 点石嘉业北京网站建设公司无锡百度正规推广
  • 网站建设维护更新铜仁搜狗推广