您的位置:首页 > 文旅 > 美景 > 上海公安门户网站网址_长春免费网站建站模板_百度热度指数排行_网页首页设计图片

上海公安门户网站网址_长春免费网站建站模板_百度热度指数排行_网页首页设计图片

2025/4/26 5:03:03 来源:https://blog.csdn.net/qq_41129811/article/details/147445559  浏览:    关键词:上海公安门户网站网址_长春免费网站建站模板_百度热度指数排行_网页首页设计图片
上海公安门户网站网址_长春免费网站建站模板_百度热度指数排行_网页首页设计图片

1、jar包准备

在项目中新增lib目录,并将如下两个文件放入lib目录下
aspose-words-15.8.0-jdk16.jar
aspose-pdf-22.9.jar

2、pom.xml配置

		<dependency><groupId>com.aspose</groupId><artifactId>aspose-pdf</artifactId><version>22.9</version><scope>system</scope><systemPath>${project.basedir}/lib/aspose-pdf-22.9.jar</systemPath></dependency>

3 去除水印配置

在项目中的resource文件夹下新增文件名为license.xml的文件

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

3、pdf转换城word代码

import com.aspose.pdf.Document;
import com.aspose.pdf.License;
import com.aspose.pdf.SaveFormat;import java.io.FileOutputStream;
import java.io.InputStream;public class PdfToWord {public static boolean getLicense() {boolean result = false;try {InputStream is = Page.class.getClassLoader().getResourceAsStream("\\license.xml"); // license.xml应放在..\WebRoot\WEB-INF\classes路径下License aposeLic = new License();aposeLic.setLicense(is);result = true;} catch (Exception e) {e.printStackTrace();}return result;}public static void main(String[] args) {getLicense();pdf2doc("文件地址");}//pdf转docpublic static void pdf2doc(String pdfPath) {long old = System.currentTimeMillis();try {//新建一个word文档String wordPath=pdfPath.substring(0,pdfPath.lastIndexOf("."))+".docx";FileOutputStream os = new FileOutputStream(wordPath);//doc是将要被转化的word文档Document doc = new Document(pdfPath);//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换doc.save(os, SaveFormat.DocX);os.close();//转化用时long now = System.currentTimeMillis();System.out.println("Pdf 转 Word 共耗时:" + ((now - old) / 1000.0) + "秒");} catch (Exception e) {System.out.println("Pdf 转 Word 失败...");e.printStackTrace();}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com