aspose word与pdf互转

package com.example.core.mydemo.aspose;

import com.aspose.words.Document;
import com.aspose.words.License;
import com.aspose.words.SaveFormat; import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream; public class WordToPdf {
public static File docToPdf(String docPath, String pdfPath) {
System.out.println("WORD转化PDF开始>>>>"); //转化用时
File pdfFile = new File(pdfPath);
try {
long old = System.currentTimeMillis();
String s = "<License><Data><Products><Product>Aspose.Total for Java</Product><Product>Aspose.Words 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>";
ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
License license = new License();
license.setLicense(is);
Document document = new Document(docPath);
FileOutputStream outputStream = new FileOutputStream(pdfFile);
document.save(outputStream, SaveFormat.PDF);
long now = System.currentTimeMillis();
outputStream.close();
is.close();
System.out.println("WORD转化PDF共耗时:" + ((now - old) / 1000.0) + "秒"); //转化用时
} catch (Exception e) {
System.out.println("转化失败");
e.printStackTrace();
}
return pdfFile;
} public static File docToPdf(InputStream docPathInputStream, String pdfPath) {
File pdfFile = new File(pdfPath);
try {
long old = System.currentTimeMillis();
String s = "<License><Data><Products><Product>Aspose.Total for Java</Product><Product>Aspose.Words 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>";
ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
License license = new License();
license.setLicense(is);
Document document = new Document(docPathInputStream);
FileOutputStream outputStream = new FileOutputStream(pdfFile);
document.save(outputStream, SaveFormat.PDF);
long now = System.currentTimeMillis();
outputStream.close();
is.close();
System.out.println("WORD转化PDF共耗时:" + ((now - old) / 1000.0) + "秒"); //转化用时
} catch (Exception e) {
System.out.println("转化失败");
e.printStackTrace();
} return pdfFile;
} public static void main(String[] args) {
String docPath = "F:\\Users\\test\\Desktop\\IT项目.docx";
String pdfPath = "F:\\Users\\test\\Desktop\\IT项目-convert1.pdf";
docToPdf(docPath,pdfPath); } }
package com.example.core.mydemo.aspose;

import com.aspose.pdf.DocSaveOptions;
import com.aspose.pdf.License;
import com.aspose.pdf.SaveFormat;
import com.aspose.pdf.Document; import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream; public class PdfToWord {
public static File pdfToDoc(String pdfPath, String docPath) {
System.out.println("PDF转化WORD开始>>>>"); //转化用时
File pdfFile = new File(docPath);
try {
long old = System.currentTimeMillis();
String s = "<License><Data><Products><Product>Aspose.Total for Java</Product><Product>Aspose.Words 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>";
ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
License license = new License();
license.setLicense(is); Document document = new Document(pdfPath);
FileOutputStream outputStream = new FileOutputStream(pdfFile);
document.save(outputStream, SaveFormat.Doc); // DocSaveOptions saveOptions = new DocSaveOptions();
// saveOptions.setMode(DocSaveOptions.RecognitionMode.Flow);
// saveOptions.setFormat(DocSaveOptions.DocFormat.DocX);
// document.save(outputStream, saveOptions); outputStream.close();
is.close();
long now = System.currentTimeMillis();
System.out.println("PDF转化WORD共耗时:" + ((now - old) / 1000.0) + "秒"); //转化用时
} catch (Exception e) {
System.out.println("转化失败");
e.printStackTrace();
}
return pdfFile;
} public static File pdfToDoc(InputStream pdfPathInputStream, String docPath) {
File pdfFile = new File(docPath);
try {
long old = System.currentTimeMillis();
String s = "<License><Data><Products><Product>Aspose.Total for Java</Product><Product>Aspose.Words 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>";
ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
License license = new License();
license.setLicense(is);
Document document = new Document(pdfPathInputStream);
FileOutputStream outputStream = new FileOutputStream(pdfFile);
document.save(outputStream, SaveFormat.Doc);
outputStream.close();
is.close();
long now = System.currentTimeMillis();
System.out.println("PDF转化WORD共耗时:" + ((now - old) / 1000.0) + "秒"); //转化用时
} catch (Exception e) {
System.out.println("转化失败");
e.printStackTrace();
}
return pdfFile;
} public static void main(String[] args) {
String pdfPath = "F:\\Users\\test\\Desktop\\IT项目.pdf";
/**
* 测试发现:只能生成doc,而不能生成docx,文件打不开。
*/
String docPath = "F:\\Users\\test\\Desktop\\IT项目-convert.doc";
pdfToDoc(pdfPath,docPath); } }

百度云:
链接:https://pan.baidu.com/s/1uskoVYZvxHnc6COWW_eAJg
提取码:qmz7

aspose word与pdf互转的更多相关文章

  1. Aspose 强大的服务器端 excel word ppt pdf 处理工具

    Aspose 强大的服务器端 excel word ppt pdf 处理工具 http://www.aspose.com/java/word-component.aspx

  2. Aspose.Words操作word生成PDF文档

    Aspose.Words操作word生成PDF文档 using Aspose.Words; using System; using System.Collections.Generic; using ...

  3. java实现word转pdf在线预览(前端使用PDF.js;后端使用openoffice、aspose)

    背景 之前一直是用户点击下载word文件到本地,然后使用office或者wps打开.需求优化,要实现可以直接在线预览,无需下载到本地然后再打开. 随后开始上网找资料,网上资料一大堆,方案也各有不同,大 ...

  4. 使用aspose.word两句代码将word转换为pdf

    //Load Document Document document = new Document(@"C:\Users\Administrator\Desktop\人事---新员工转正总结( ...

  5. Jacob工具类使用文件互转服务 word转html html转excel word转pdf excel转pdf ppt转pdf

    前提条件  必须安装MS office 1.jdk使用jdk1.8 2.jacob.dll放在..\jdk1.8\jre\bin目录下 3.eclipse的jre版本要和jdk一致,window-&g ...

  6. Aspose.word直接转pdf

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  7. C#实现 word、pdf、ppt 转为图片

    office word文档.pdf文档.powerpoint幻灯片是非常常用的文档类型,在现实中经常有需求需要将它们转换成图片 -- 即将word.pdf.ppt文档的每一页转换成一张对应的图片,就像 ...

  8. word转pdf字体格式变乱的问题

    完成word转pdf的功能之后,本地测试没问题,然后发布到服务器上,就遇到了字体变乱的问题,如下: 由于我本地发布后导出没有出现同样情况,而服务器和本地的最大区别在于字体库,于是,把服务器上关于需要用 ...

  9. word、pdf、ppt 转为图片

    office word文档.pdf文档.powerpoint幻灯片是非常常用的文档类型,在现实中经常有需求需要将它们转换成图片 -- 即将word.pdf.ppt文档的每一页转换成一张对应的图片,就像 ...

  10. ASP.NET实现在线浏览Word文档另一种解决方案(Word转PDF)

    ASP.NET实现在线浏览Word文档另一种解决方案(Word转PDF)      上述博文里提到的在线浏览pdf的方案不错,但word转pdf的那个dll只支持doc不支持docx,附上最新的下载链 ...

随机推荐

  1. 如何通过 Serverless 提高 Java 微服务治理效率?

    简介: 在业务初期,因人手有限,想要快速开发并上线产品,很多团队使用单体的架构来开发.但是随着公司的发展,会不断往系统里面添加新的业务功能,系统越来越庞大,需求不断增加,越来越多的人也会加入到开发团队 ...

  2. HttpClient配置SSL绕过https证书以及双向认证

    HttpClient简介 1.HTTP 协议是 Internet 上使用得最多.最重要的协议之一,越来越多的 Java 应用程序需要直接通过 HTTP 协议来访问网络资源.虽然在 JDK 的 java ...

  3. 一个可以输出当前移动设备机型(安卓,ios)系统版本的html页面

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. SAP集成技术(七)集成解决方案咨询方法论(ISA-M)

    目前,ISA-M 主要以 Microsoft PowerPoint 演示文稿的形式提供.可以在 SAP Community 博客文章(https://blogs.sap.com/)以及关于ISA-M ...

  5. 【爬虫数据集】李子柒YouTube频道TOP10热门视频的TOP2000热门评论,共计2W条

    目录 一.背景 二.爬取目标 三.结果展示 四.演示视频 五.附完整数据 一.背景 这段时间,有超多小伙伴找我要YouTube数据,做数据分析.情感分析之类的研究工作,但很多人并不是计算机软件相关专业 ...

  6. 4、Linux 网络基础

    1.基础命令 hostname:查看或设置当前主机名 route [-n]:查看或设置主机中路由表信息 netstat:查看系统的网络连接状态.路由表.接口统计等信息 常用选项 -a:显示所有-n:以 ...

  7. H5页面制作和CSS3动画的结合

    现在很火的是h5页面的开发,更多的视觉冲击,带来更多的关注度,更多的眼球,想要别人看你的东西,不在是以前的一段文字,或是一个图片的时代了,现在h5把一张张图片,一段段文字动起来,更有与客户的交互,而且 ...

  8. Python:用Pandas输出格式化HTML并高亮

    输出格式化的HTML 我们已知一个DataFrame记录了模型Model1.Model2在3个Epoch优化中的精度变化情况: frame = pd.DataFrame({"Model1&q ...

  9. 通过XML标记生成word

    思路 word生成可以通过标签,也可以通过XML元素. word文档实际上是由文档对象模型描述的,因此我们能够通过对文档对象进行操作去生成word. 由于word允许我们附加XML结构(元素),如下: ...

  10. HC32L110(六) AS06-VTB07H V5.0测试板AT指令固件

    目录 HC32L110(一) HC32L110芯片介绍和Win10下的烧录 HC32L110(二) HC32L110在Ubuntu下的烧录 HC32L110(三) HC32L110的GCC工具链和VS ...