将java工程导成jar包 使用 bat 执行 jar 包。

---------------------------------------------------------------------------------------------------------------

eclipse 工程

  1. Pdf2Word.java 解析pdf主类。
  2. laq_.txt             操作说明。
  3. license.xml       aspose license。
  4. 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 高效不失真的更多相关文章

  1. java PDF转word的初步实现

    package com.springboot.springboot.util; import java.io.File; import java.io.FileOutputStream; import ...

  2. java实现word转pdf文件(高效不失真)

    import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import org.aspectj ...

  3. Java解析OFFICE(word,excel,powerpoint)以及PDF的实现方案及开发中的点滴分享

    Java解析OFFICE(word,excel,powerpoint)以及PDF的实现方案及开发中的点滴分享 在此,先分享下写此文前的经历与感受,我所有的感觉浓缩到一个字,那就是:"坑&qu ...

  4. 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 ...

  5. 15个最好的PDF转word的在线转换器,将PDF文件转换成doc文件

    PDF是一种文件格式,包含文本,图像,数据等,这是独立于操作系统的文件类型.它是一个开放的标准,压缩,另一方面DOC文件和矢量图形是由微软文字处理文件.该文件格式将纯文本格式转换为格式化文档.它支持几 ...

  6. iText导出pdf、word、图片

    一.前言 在企业的信息系统中,报表处理一直占比较重要的作用,本文将介绍一种生成PDF报表的Java组件--iText.通过在服务器端使用Jsp或JavaBean生成PDF报表,客户端采用超级连接显示或 ...

  7. java 如何将 word,excel,ppt如何转pdf--jacob

    问题:java 如果将 word,excel,ppt如何转pdf 我个人的观点:windows server下用 jacob; linux server下 用openoffice.   PS:1.本文 ...

  8. CAJ Viewer安装流程以及CAJ或Pdf转换为Word格式

        不多说,直接上干货! pdf转word格式,最简单的就是,实用工具 Adobe Acrobat DC 首先声明的是,将CAJ或者Pdf转换成Word文档,包括里面的文字.图片以及格式,根本不需 ...

  9. asp.net导出excel-一行代码实现excel、xml、pdf、word、html、csv等7种格式文件导出功能而且美观-SNF快速开发平台

    分享: 腾讯微博  新浪微博   搜狐微博   网易微博  腾讯朋友  百度贴吧  豆瓣   QQ好友  人人网 作者:王春天  原文地址:http://www.cnblogs.com/spring_ ...

随机推荐

  1. python中os.path模块简介

    1.python中获取当前工作目录 curDir = os.getcwd() os.getcwd()返回的是执行命令时所在的目录,而不是脚本本身所在的目录 2.os.path os.path.absp ...

  2. genymotion virtual device 用迅雷下载

    找到虚拟机下载Log文件 打开后,找到原来下载的地址 以ova结尾的文件,然后用迅雷下载这个文件. 下载好的文件放在 C:\Users\用户名\AppData\Local\Genymobile\Gen ...

  3. 阿里云短信验证使用(PHP)

    1.登陆阿里云后台,事先添加签名和模板 2.使用composer下载阿里云SDK composer require alibabacloud/sdk 在PHP7.0下安装需要提前安装curl扩展 -c ...

  4. Java学习--泛型

    个人理解,所谓的泛型就是将数据类型像参数(称为类型参数或者泛型参数)一样传入类,接口或者方法中,这个类型参数可以当作普通的数据类型,进行变量的声明(成员变量,局部变量(包括方法参数)),指明返回值类型 ...

  5. ActiveMq Windows 配置优化

    最近ActiveMQ 5.15.3 会报 OutofMemory的错误 在 wrapper.conf中 #wrapper.java.additional.8=-Dorg.apache.activemq ...

  6. dwSun带你选Python的编辑器/IDE

    dwSun带你选Python的编辑器/IDE Python 是一门简单易学,同时又十分强大的编程语言.特别是随着人工智能的热潮,Python作为AI开发的首选语言,已经是技术人员的必备技能. 在学习和 ...

  7. H5自定义金额键盘,改良后ios体验效果流畅

    下载的别人的插件改良一下,源码地址:https://github.com/XieTongXue/how-to/tree/master/pay-h5 没有插件,直接来代码 <div class=& ...

  8. Scratch 数字游戏

    本想用Scratch给女儿做一个类似舒尔特方格的程序来认识数字和提升专注,想想这对刚刚3岁的孩子来说还是比较困难的,于是只做了3*3的方格,来认识数字1-9. 游戏地址:Random 9 v0.21 ...

  9. 使用百度ocr接口识别验证码

    #!/usr/bin/env python #created by Baird from aip import AipOcr def GetCaptchaV(filename): APP_ID = ' ...

  10. 交叉熵理解:softmax_cross_entropy,binary_cross_entropy,sigmoid_cross_entropy简介

    cross entropy 交叉熵的概念网上一大堆了,具体问度娘,这里主要介绍深度学习中,使用交叉熵作为类别分类. 1.二元交叉熵 binary_cross_entropy 我们通常见的交叉熵是二元交 ...