最近有一些学习资料大概几个G,搞得全是PDF。没办法编辑。所以就想转成word。但是搜了很多软件没有批量转换功能。只能一个一个处理,太浪费时间。最主要的还是全部收费。所以决定自己写一个还能节省时间。

需要注意的事项:jar包必须破解,如果不是破解版每个文档只能转换4页。

怎么破解jar包网上有教程感兴趣的可以自己破解一下。我就不写了。

jar包资源:aspose-pdf.zip-互联网文档类资源-CSDN下载

1.将需要的aspose.pdf.jar包引入项目

2.封装读取文件夹里面PDF文件的工具类

package com.question.syncdemo.utils;import cn.hutool.core.io.file.FileReader;
import cn.hutool.core.util.StrUtil;import java.io.File;
import java.util.ArrayList;
import java.util.List;/*** description: FileUtils  文件操作工具类<br>** @date: 2020/11/17 0017 下午 5:06 <br>* @author: William <br>* version: 1.0 <br>*/
public class FileUtils {//因为我这个是临时用所以没有考虑并发,如果并发自己修改一下就好了public static List<String> resultList = new ArrayList<>();/***@description: 通过文件路径,修改该路径下所有文件的名字* @param path  文件夹路径* @return:* @author: William* @date 2019/8/8 14:52*/public static List<String> getFilesPaths(String path,List<String> stringList){File file = new File(path);if(file.exists()){File[] files = file.listFiles();if (null == files || files.length == 0) {System.out.println("文件夹是空的!");} else {for (File file2 : files) {if (file2.isDirectory()) {getFilesPaths(file2.getAbsolutePath(),stringList);} else {String filePath = file2.getAbsolutePath();stringList.add(filePath);}}}}else{System.out.println("该路径不存在");}return stringList;}}

3.封装PDF处理工具类

package com.question.syncdemo.utils;import com.aspose.pdf.Document;
import com.aspose.pdf.License;
import com.aspose.pdf.SaveFormat;import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference;/*** description: PDFUtil <br>** @date: 2021/2/4 0004 上午 10:09 <br>* @author: William <br>* version: 1.0 <br>*/
public class PDFUtil {private static InputStream license;public static void main(String[] args) throws Exception {pdf2word();}//多线程处理需要转换格式的文件public static void produceData(List<String> list) throws InterruptedException {//每个线程处理的数据,我这里只开了三个线程,int threadSize = list.size()/3;//int threadSize = 500;  可以每个线程处理500条数据int remainder = list.size() % threadSize;//线程数int threadNum = 0;if (remainder == 0) {threadNum = list.size() / threadSize;} else {threadNum = list.size() / threadSize + 1;}long begin = System.currentTimeMillis();//创建一个线程池ExecutorService eService = Executors.newFixedThreadPool(threadNum);List<Callable<String>> cList = new ArrayList<>();Callable<String> task = null;List<String> sList = null;for (int i = 0; i < threadNum; i++) {if (i == threadNum - 1) {sList = list.subList(i * threadSize, list.size());} else {sList = list.subList(i * threadSize, (i + 1) * threadSize);}final List<String> nowList = sList;task = new Callable<String>() {@Overridepublic String call() throws Exception {nowList.forEach(filesPath -> {if(filesPath.contains(".pdf")){File file = new File(filesPath);String paperName = file.getName();paperName = paperName.substring(0,paperName.lastIndexOf("."));String tempFilesPath = filesPath.substring(0,filesPath.lastIndexOf(File.separator));tempFilesPath = tempFilesPath +"\\"+paperName+".docx";System.out.println(tempFilesPath);try {saveAsWord(filesPath,tempFilesPath);} catch (Exception e) {e.printStackTrace();}}});return "ok";}};cList.add(task);}List<Future<String>> results = eService.invokeAll(cList);for (Future<String> str : results) {//System.out.println(str.get());}eService.shutdown();long end = System.currentTimeMillis();System.out.println("执行耗时:" + (end - begin));}public static void pdf2word() throws Exception {List<String> strings = new ArrayList<>();List<String> filesPaths = FileUtils.getFilesPaths("D:\\work\\temp\\中学学段2019科目二", strings);produceData(filesPaths);}//将PDF保存为wordpublic static void saveAsWord(String targetFile,String newFile) throws Exception {File target = new File(targetFile);if(!target.exists()){target.mkdirs();}FileInputStream targetInputStream = new FileInputStream(target);//调用去水印的方法 读取license.xml文件if (!getLicense()) {System.out.println("获取验证失败");}Document targetDocument = new Document(targetInputStream);targetDocument.save(newFile, SaveFormat.DocX);targetInputStream.close();targetDocument.close();}//证书获取public static synchronized boolean getLicense() {boolean result = false;try {String license2 = "<License>\n"+ "  <Data>\n"+ "    <Products>\n"+ "      <Product>Aspose.Total for Java</Product>\n"+ "      <Product>Aspose.Words for Java</Product>\n"+ "    </Products>\n"+ "    <EditionType>Enterprise</EditionType>\n"+ "    <SubscriptionExpiry>20991231</SubscriptionExpiry>\n"+ "    <LicenseExpiry>20991231</LicenseExpiry>\n"+ "    <SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>\n"+ "  </Data>\n"+ "  <Signature>111</Signature>\n"+ "</License>";license = new ByteArrayInputStream(license2.getBytes("UTF-8"));License aposeLic = new License();aposeLic.setLicense(license);result = true;} catch (Exception e) {e.printStackTrace();}return result;}}

如果没有币的直接加我微信获取就好了

Java使用aspose批量将PDF转为word相关推荐

  1. 批量将 PDF 转为 Word 文档,支持 Docx、Doc 格式

    概要:PDF 和 Word 这两种格式是非常常见的,并且相互之间也经常需要进行格式转化.Word 转 PDF是非常容易就能做到的,但是 PDF 转 Word 就经常会碰到各种各样的问题,比如格式错乱. ...

  2. 手把手 | 20行Python代码教你批量将PDF转为Word

    2019独角兽企业重金招聘Python工程师标准>>> 在日常工作或学习中,经常会遇到这样的无奈: "小任,你把这个PDF中的文件码出来发我" 艹,倒霉,2M的P ...

  3. 用ASPOSE将PDF转为word(解除页数限制和去水印)

    相关链接 https://xie.infoq.cn/article/7d475ca4d2eb4632c2459fe05 https://github.com/xinxiamu/java-core/bl ...

  4. java pdf 转换 word_Java 将PDF 转为Word、图片、SVG、XPS、Html、PDF/A

    本文将介绍通过Java编程来实现PDF文档转换的方法.包括: 1. PDF转为Word 2. PDF转为图片 3. PDF转为Html 4. PDF转为SVG 4.1将PDF每一页转为单个的SVG 4 ...

  5. Java 将PDF转为Word

    众所周知,PDF文档除了具有较强稳定性和兼容性外, 还具有较强的安全性,在工作中可以有效避免别人无意中对文档内容进行修改.但与此同时,也妨碍了对文档的正常修改.这时我们可以将PDF转为Word文档进行 ...

  6. Java 将PDF 转为Word、图片、SVG、XPS、Html、PDF/A

    本文将介绍通过Java编程来实现PDF文档转换的方法.包括: 1. PDF转为Word 2. PDF转为图片 3. PDF转为Html 4. PDF转为SVG 4.1 将PDF每一页转为单个的SVG4 ...

  7. 如何将pdf转为word使用?

    如何将pdf转为word使用?为什么我们要将pdf文件转换成word再使用呢,因为pdf文件是一种比较稳定的文件格式,它不好编辑,转成word后我们就能随意对文件内容进行编辑修改.由于pdf文件越来越 ...

  8. 基于pdf2docx模块Python实现批量将PDF转Word文档(安装+完整代码教程)

    PDF文件是一种常见的文档格式,但是在编辑和修改时不太方便,因为PDF本质上是一种静态的文档格式.因此,有时候我们需要将PDF文件转换成Word格式,以便更好地编辑和修改文档.在本篇文章中,我们将介绍 ...

  9. 用Python把PDF转为Word方法总结

    先讲一下为啥要写这个文章,网上其实很多这种PDF转化的代码和软件.我一直想用Python做,但是网上搜到的代码很多都不能用,很多是2.7版本的代码,再就是PDF需要用到的库在导入的时候,很多的报错,解 ...

最新文章

  1. torch量化感知训练示例项目
  2. Struts2数据传输的背后机制:ValueStack(值栈)
  3. Linux下文件权限查看并使用chomd修改文件权限
  4. Scikit-Learn 与 TensorFlow 机器学习实用指南学习笔记1 — 机器学习基础知识简介
  5. android shell检查是否锁屏_ADB获取手机屏幕的状态(点亮与否)以及ADB点击事件基本操作...
  6. 网络协议 反扒机制 fidder 抓包工具
  7. websocket.onmessage回调没反应_等待A股暴跌回调补四缺口倒计时第二十四天——8月19日总结...
  8. php原生判断,JavaScript
  9. 或许是 Nginx 上配置 HTTP2 最实在的教程了
  10. 《解忧杂货店》读后感:路一直都在,进步就是幸福
  11. python教程(八)之异常(8.Warn)
  12. OpenCV 3.0 高动态范围图像
  13. 红包码收款码合二为一
  14. 日本首次利用iPS视细胞治疗视网膜色素变性
  15. 超好用的手机录屏软件推荐
  16. ElasticSearch 从5.6.3升级到7.9.3遇到问题总结
  17. C语言(二级基础知识2)
  18. 内容营销的思维方式 阿胜说
  19. ElasticSearch--分片和副本--原理
  20. phoenix简介及安装(附安装包)

热门文章

  1. error LNK2019:和error LNK2001:
  2. matlab图源代码,[转载]常用的一些图像处理Matlab源代码
  3. 通过微博名查看id html,微博id在哪里查看?
  4. 计算机word表格基础,Word表格的作-计算机基础.doc
  5. 高清动图如何制作 GIF表情包制作方法
  6. python dataframe index_Python将DataFrame的某一列作为index的方法
  7. AIS 2019(ACL IJCAI SIGIR)论文研讨会研究趋势汇总
  8. Verilog语法-005—宏定义
  9. 如何制作点餐小程序?
  10. 深入理解数据库当中的聚合函数