java pdf转word 高效不失真
将java工程导成jar包 使用 bat 执行 jar 包。
---------------------------------------------------------------------------------------------------------------
eclipse 工程

- Pdf2Word.java 解析pdf主类。
- laq_.txt 操作说明。
- license.xml aspose license。
- aspose.pdf-11.5.0.jar 转word所需jar包 可在 aspose 官网 https://docs.aspose.com/display/pdfnet/Printing+PDF+Document 下载
---------------------------------------------------------------------------------------------------------------
附源码
Pdf2Word.java
package com.bxj;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import com.aspose.pdf.Document;
import com.aspose.pdf.License;
import com.aspose.pdf.SaveFormat;
public class Pdf2Word {
public static boolean getLicense() {
boolean result = false;
try
{
InputStream license = ClassLoader.getSystemResourceAsStream("license.xml");
License aposeLic = new License();
aposeLic.setLicense(license);
result = true;
}
catch (Exception e)
{
System.out.println("license not found!");
}
return result;
}
public static void main(String[] args) {
try
{
if (!getLicense()) {
return;
}
String pdfFile = args[0];
pdfFile = pdfFile.replace("\\", "/");
AnalyzePdf pdf=new AnalyzePdf(pdfFile);
AnalyzeTxt txt=new AnalyzeTxt();
Thread t1=new Thread(pdf);
Thread t2=new Thread(txt);
t1.start();
t2.start();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
class AnalyzePdf implements Runnable{
String fileDir;
public AnalyzePdf(String fileDir){
this.fileDir = fileDir;
}
@Override
public void run()
{
recursion(fileDir);
}
private static void recursion(String fileDir)
{
File file = new File(fileDir);
File[] files = file.listFiles();// 获取目录下的所有文件或文件夹
if (files == null)
{
return;
}
for (File f : files)
{
if (f.isFile() && f.getName().endsWith(".pdf"))
{
pdf2word(f);
}
else if (f.isDirectory())
{
//递归
recursion(f.getAbsolutePath());
}
}
}
private static void pdf2word(File pdfFile)
{
try {
InputStream fileInput = new FileInputStream(pdfFile);// 待处理的文件
Document pdfDocument = new Document(fileInput);
String fileName = pdfFile.getAbsolutePath().replace("pdf", "doc");
File file = new File(fileName);
if (!file.exists())
{
file.createNewFile();
}
OutputStream fileOutput = new FileOutputStream(fileName);
pdfDocument.save(fileOutput, SaveFormat.DocX);
} catch (Exception e) {
e.printStackTrace();
}
}
public String getFileDir()
{
return fileDir;
}
public void setFileDir(String fileDir)
{
this.fileDir = fileDir;
}
}
class AnalyzeTxt implements Runnable{
@Override
public void run()
{
try
{
InputStream inputStream = ClassLoader.getSystemResourceAsStream("laq_.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
int c;
while((c=reader.read()) != -1){
if(c!= 32){
Thread.sleep(1);
}
System.out.print((char)c);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
laq_.txt
- 将需转换的pdf文件置于 out 目录
- 输出文件在 out 目录查看
license.xml
<License>
<Data>
<Products>
<Product>Aspose.Total for Java</Product>
<Product>Aspose.Pdf for Java</Product>
</Products>
<EditionType>Enterprise</EditionType>
<SubscriptionExpiry>20991231</SubscriptionExpiry>
<LicenseExpiry>20991231</LicenseExpiry>
<SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>
</Data>
<Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>
</License>
MANIFEST.MF
Manifest-Version: 1.0
Class-Path: lib/aspose.pdf-11.5.0.jar
Main-Class: com.bxj.Pdf2Word
---------------------------------------------------------------------------------------------------------------
导为 jar 包



导出目录

lib 存放 aspose.pdf-11.5.0.jar
out 存放 转换的pdf文件 (转换完成的word文件也在这个路径)
运行.bat 批处理文件
@echo off
set current_path=%cd%\out
java -jar -Xms4000m -Xmx4000m -Xmn2000m Pdf2Word_LAQ.jar %current_path%
@pause
欢迎关注 有疑问可交流
java pdf转word 高效不失真的更多相关文章
- java PDF转word的初步实现
package com.springboot.springboot.util; import java.io.File; import java.io.FileOutputStream; import ...
- java实现word转pdf文件(高效不失真)
import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import org.aspectj ...
- Java解析OFFICE(word,excel,powerpoint)以及PDF的实现方案及开发中的点滴分享
Java解析OFFICE(word,excel,powerpoint)以及PDF的实现方案及开发中的点滴分享 在此,先分享下写此文前的经历与感受,我所有的感觉浓缩到一个字,那就是:"坑&qu ...
- 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 ...
- 15个最好的PDF转word的在线转换器,将PDF文件转换成doc文件
PDF是一种文件格式,包含文本,图像,数据等,这是独立于操作系统的文件类型.它是一个开放的标准,压缩,另一方面DOC文件和矢量图形是由微软文字处理文件.该文件格式将纯文本格式转换为格式化文档.它支持几 ...
- iText导出pdf、word、图片
一.前言 在企业的信息系统中,报表处理一直占比较重要的作用,本文将介绍一种生成PDF报表的Java组件--iText.通过在服务器端使用Jsp或JavaBean生成PDF报表,客户端采用超级连接显示或 ...
- java 如何将 word,excel,ppt如何转pdf--jacob
问题:java 如果将 word,excel,ppt如何转pdf 我个人的观点:windows server下用 jacob; linux server下 用openoffice. PS:1.本文 ...
- CAJ Viewer安装流程以及CAJ或Pdf转换为Word格式
不多说,直接上干货! pdf转word格式,最简单的就是,实用工具 Adobe Acrobat DC 首先声明的是,将CAJ或者Pdf转换成Word文档,包括里面的文字.图片以及格式,根本不需 ...
- asp.net导出excel-一行代码实现excel、xml、pdf、word、html、csv等7种格式文件导出功能而且美观-SNF快速开发平台
分享: 腾讯微博 新浪微博 搜狐微博 网易微博 腾讯朋友 百度贴吧 豆瓣 QQ好友 人人网 作者:王春天 原文地址:http://www.cnblogs.com/spring_ ...
随机推荐
- Attempted to serialize java.lang.Class: org.hibernate.proxy.HibernateProxy. Forgot to register a type adapter?
当我们使用gson 转对象时,并且这个对象中有一些属性是懒加载时如 @Entity @Table(name = "user") public class User { @Id @C ...
- New York is 3 hours ahead of California
New York is 3 hours ahead of California, 纽约时间比加州时间早三个小时, but it does not make California slow. 但加州时间 ...
- R语言输出高质量图片
Rstudio画图之后保存的 图片格式如下 上面的几种格式可以直接插入word文档中,但是图片质量很低,锯齿感很明显.若生成PDF,为矢量图(不懂),但是不可以插入word文档中. 最简便的方法就是对 ...
- zabbix通过agent添加监控项的步骤
1.确定要监控的对象的指标 2.在agent端上,把如何具体获取指标写成shell脚本,并放在一个和其它agent端统一的位置上 3.在agent端上,自定义监控项key值,配置zabbix_agen ...
- 【396】python 递归练习题(COMP9021)
Merging two strings into a third one Say that two strings s1 and s2 can be merged into a third strin ...
- promise.then, setTimeout,await执行顺序问题
promise.then VS setTimeout 在chrome和node环境环境中均输出2, 3, 1, 先输出2没什么好说的,3和1顺序让人有些意外 原因: 有一个事件循环,但是任务队列可以有 ...
- Loadrunner回放https脚本时出现错误Error -27780 Connection reset by peer解决办法
录制好的https协议的web脚本,在脚本回放时会出现Error -27780: [GENERAL_MSG_CAT_SSL_ERROR]connect to host "......&quo ...
- 基础算法简单实现-python
目录 Python(版本3.6+)-Anna-Lena Popkes
- Ubuntu搜狗拼音输入法崩溃问题
Ubuntu 14.04.5 LTS 环境下搜狗拼音经常崩溃,似乎也没有什么特别好的解决办法. 以下是重启命令 #!/bin/sh >/dev/>& >/dev/>&a ...
- Python中函数和方法的区别
方法是一种特殊的函数属于某个类的的函数叫方法不属于某个类的函数叫函数 转自csdn https://blog.csdn.net/weixin_40380298/article/details/7825 ...