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. [Caddy2] Caddyfile 使用其它 DNS provider

    安装 caddy 的 dns provider 模块. https://github.com/caddy-dns/cloudflare 如果是在 Docker 中 build 模块按文档进行,通过 c ...

  2. [FAQ] JS 时间戳格式化为 date

    拷贝使用,不用引入第三方库 function formatDate (date = 0, fmt = 'yyyy-MM-dd hh:mm:ss') { date = new Date(+date) i ...

  3. win10 uwp 简单制作一个 Path 路径绘制的图标按钮

    本文告诉大家在 UWP 或 WinUI 3 里面如何简单制作一个由 Path 几何路径图形绘制的图标按钮 先在资源里面定义按钮的样式,重写 Template 属性,通过在 Template 里面放入 ...

  4. WPF 使用 MAUI 的自绘制逻辑

    这是一个当前还没开发完成的功能,准确来说连预览版也算不上的功能.我原本以为 MAUI 是无法在 WPF 上面跑的,然而在看完了 MAUI 整个大的设计,才了解到,原来 MAUI 是一个非常庞大的开发项 ...

  5. Postergresql常见操作

    Postergresql常见操作 1. 安装部署 略 2. 登录数据库 查看版本 ## 以管理员身份 postgres 登陆,然后通过#psql -U postgres#sudo -i -u post ...

  6. pod QoS等级(A)

    一.了解Pod Qos等级 一个节点不一定能提供所有pod所指定的资源limits之和那么多的资源量. 假设有两个pod,pod A使用了节点内存的 90%,pod B突然需要比之前更多的内存,这时节 ...

  7. 什么是SQL 语句中相关子查询与非相关子查询

    1.什么是SQL子查询 要理解相关子查询和非相关子查询,我们得首先理解什么是子查询,子查询是指在一个查询语句中嵌套的另一个查询语句. 子查询可以嵌套在其他查询语句中,如 SELECT.INSERT.U ...

  8. VSCode+VUE+ESLint以达到保存自动格式化

    首先打开VSCode在.eslintrc.js中加入以下代码(不知道怎么找可以ctrl+shift+p进行搜索),添加 vscode 终端启动服务 // 添加⾃定义规则 'prettier/prett ...

  9. GOLANG-配置nginx反向代理端口 配置域名

    目录 配置/etc/nginx/nginx.conf文件 新建/etc/nginx/conf.d/doc.haimait.conf文件 重启nginx服务 解析自己的域名到服务器的公网ip 配置/et ...

  10. tomcat(1)- tomcat服务介绍与安装

    目录 1. Tomcat介绍 2. Tomcat安装 2.1 JDK安装 2.2 Tomcat安装 3. Tomcat打开默认的管理页面 1. Tomcat介绍 JVM简介 JAVA应用都是运行在ja ...