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. 每次都需要解释大量指令?使用 PolarDB-X 向量化引擎

    简介: 向量化引擎为PolarDB-X的表达式计算带来了显著的性能提升. 介绍 PolarDB-X是阿里巴巴自研的云原生分布式数据库,采用了计算-存储分离的架构,其中计算节点承担着大量的表达式计算任务 ...

  2. 阿里云EMR Remote Shuffle Service在小米的实践

    ​简介:阿里云EMR自2020年推出Remote Shuffle Service(RSS)以来,帮助了诸多客户解决Spark作业的性能.稳定性问题,并使得存算分离架构得以实施,与此同时RSS也在跟合作 ...

  3. Serverless Devs 2.0 开箱测评:Serverless 开发最佳实践

    ​简介: 当下,Serverless 概念很火,很多同学被 Serverless 的优势吸引过来,比如它的弹性伸缩,免运维,高可用,资费少.但真正使用起来去落地的时候发现问题很多,大型项目如何组织函数 ...

  4. [FAQ] Windows 终端 git status 不识别文件名大小写的修改

      当我们修改了文件名的大小写,git status 显示没有文件改动. 出现这种情况,首先看一下 git 的配置项是否忽略了文件问大小写: $ git config core.ignorecase ...

  5. WPF 关于将 ManipulationDeltaEventArgs 的 Manipulators 属性返回值修改为 ReadOnlyCollection 类型的提议

    这是一个 WPF 框架的 API 变更提议,记录一下博客 讨论的地方是: How about change the type of ManipulationDeltaEventArgs.Manipul ...

  6. WPF 简单判断主线程界面是否卡顿的方法

    本文来告诉大家如何使用简单的代码判断当前的软件的 UI 线程或界面是否卡顿 在后台线程调用如下代码即可用来判断是否卡顿 private static async Task<bool> Ch ...

  7. WPF 基于 Azure 的认知服务 情绪分析 语言检测 关键短语提取

    本文主要是来安利大家基于 Azure 的认知服务,主要是文本认知服务,可以做到分析输入文本的情绪,以及判断当前输入文本所属语言等功能 本文分为两个部分 ,一个就是在 Azure 上的配置,另一个就是 ...

  8. .net 记录http请求

    记录http请求 环境 .net7 一.过滤器(Filter) 这个过程用的的是操作过滤器(ActionFilter) 二. 2.1 继承IAsyncActionFilter 2.2 重写OnActi ...

  9. go实现发送邮件验证码

    目录 开启SMTP服务: 发邮件测试 业务实现 开启SMTP服务: QQ邮箱参考下面连接: QQ邮箱如何开通SMTP服务 https://jingyan.baidu.com/article/00a07 ...

  10. 虚拟机中安装mysql 完整教程( CentOS7 版本)

    一.检查是否安装了Mysql Yum检查 yum list installed | grep mysql 安装则直接删除 yum remove mysql-community-client.x86_6 ...