aspose word与pdf互转
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互转的更多相关文章
- Aspose 强大的服务器端 excel word ppt pdf 处理工具
Aspose 强大的服务器端 excel word ppt pdf 处理工具 http://www.aspose.com/java/word-component.aspx
- Aspose.Words操作word生成PDF文档
Aspose.Words操作word生成PDF文档 using Aspose.Words; using System; using System.Collections.Generic; using ...
- java实现word转pdf在线预览(前端使用PDF.js;后端使用openoffice、aspose)
背景 之前一直是用户点击下载word文件到本地,然后使用office或者wps打开.需求优化,要实现可以直接在线预览,无需下载到本地然后再打开. 随后开始上网找资料,网上资料一大堆,方案也各有不同,大 ...
- 使用aspose.word两句代码将word转换为pdf
//Load Document Document document = new Document(@"C:\Users\Administrator\Desktop\人事---新员工转正总结( ...
- 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 ...
- Aspose.word直接转pdf
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- C#实现 word、pdf、ppt 转为图片
office word文档.pdf文档.powerpoint幻灯片是非常常用的文档类型,在现实中经常有需求需要将它们转换成图片 -- 即将word.pdf.ppt文档的每一页转换成一张对应的图片,就像 ...
- word转pdf字体格式变乱的问题
完成word转pdf的功能之后,本地测试没问题,然后发布到服务器上,就遇到了字体变乱的问题,如下: 由于我本地发布后导出没有出现同样情况,而服务器和本地的最大区别在于字体库,于是,把服务器上关于需要用 ...
- word、pdf、ppt 转为图片
office word文档.pdf文档.powerpoint幻灯片是非常常用的文档类型,在现实中经常有需求需要将它们转换成图片 -- 即将word.pdf.ppt文档的每一页转换成一张对应的图片,就像 ...
- ASP.NET实现在线浏览Word文档另一种解决方案(Word转PDF)
ASP.NET实现在线浏览Word文档另一种解决方案(Word转PDF) 上述博文里提到的在线浏览pdf的方案不错,但word转pdf的那个dll只支持doc不支持docx,附上最新的下载链 ...
随机推荐
- [GF] 与 Laravel 设计相近的 Golang 框架 GoFrame
在 GoFrame (gogf/gf) 框架中有明确的代码分层设计,分别是 api, service, dao, model. model (结构模型)一般由工具自动生成,用于定义数据结构,只可被 m ...
- VGA显示文字
VGA显示文字 VGA字符显示的原理 把要显示的字符转换成字符点阵,然后编码存储,着色的部分为1,其它为0.然后在VGA上输出显示. 字符点阵生成软件: https://www.zhetao.com/ ...
- Solution Set - NOI真题
NOI2024 RP++! NOI2018 Day1T1 Link&Submission. 考虑一个最高的水位线使所有点通过没有积水的边就可以连通,也就是求出了一棵海拔的最大生成树.会发现只有 ...
- Solution Set - 组合计数
CF40E Number Table Link&Submission. 显然 \(n,m\) 奇偶性不同时无解.奇偶性相同时,假设有一行全为空,剩下每行至少一个有空,则除这些位置外没有限制的位 ...
- (更新中)Python、JavaScript、Java和C++语言的语法对比与梳理
目录 引言 1. 构造函数 Python JavaScript Java C++ 2. 构造类 Python JavaScript Java C++ 3. 总结 引言 在开发过程中不免需要用到多种编程 ...
- link标签的media属性
media属性表示被链接的文档将显示在什么设备上.比如下面的例子: <head> <link rel="stylesheet" type="text/c ...
- CompletableFuture学习总结
CompletableFuture 简介 在Java8中,CompletableFuture提供了非常强大的Future的扩展功能,可以帮助我们简化异步编程的复杂性,并且提供了函数式编程的能力,可以通 ...
- 🔥🔥v1.9.2-httpsok快速申请免费谷歌SSL证书
v1.9.2-httpsok快速申请免费谷歌SSL证书 介绍 httpsok 是一个便捷的 HTTPS 证书自动续签工具,专为 Nginx .OpenResty 服务器设计.已服务众多中小企业,稳定. ...
- 前端使用 Konva 实现可视化设计器(10)- 对齐线
请大家动动小手,给我一个免费的 Star 吧~ 大家如果发现了 Bug,欢迎来提 Issue 哟~ github源码 gitee源码 示例地址 不知不觉来到第 10 章了,感觉接近尾声了... 对齐线 ...
- PageOffice——动态填充Word模板并在线编辑
说明:使用pageoffice动态给word模板填充数据,插入图片.excel.word格式的文件和创建表格 一.准备工作: 本地创建一个doc或者docx格式的文件,在文件中需要插入数据的地方设置以 ...