栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Java中的Docx至Pdf转换器

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java中的Docx至Pdf转换器

这样做的主要问题是这些

PdfOptions
PdfConverter
不是
apachepoi
项目的一部分。它们是由开发的
opensagres
,第一个版本的命名错误
org.apache.poi.xwpf.converter.pdf.PdfOptions
org.apache.poi.xwpf.converter.pdf.PdfConverter
。这些老班没有更新从2014年开始,需要版本
3.9

apache poi
使用。

请使用更多
最新版本的fr.opensagres.poi.xwpf.converter.pdf,该版本可以使用最新的稳定版本进行工作

apachepoi 3.17

然后做

import java.io.InputStream;import java.io.OutputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.File;//needed jars: fr.opensagres.poi.xwpf.converter.core-2.0.1.jar, //  fr.opensagres.poi.xwpf.converter.pdf-2.0.1.jar,//  fr.opensagres.xdocreport.itext.extension-2.0.1.jar,//  itext-2.1.7.jar import fr.opensagres.poi.xwpf.converter.pdf.PdfOptions;import fr.opensagres.poi.xwpf.converter.pdf.PdfConverter;//needed jars: apache poi and it's dependenciesimport org.apache.poi.xwpf.usermodel.XWPFdocument;public class DOCXToPDFConverterSampleMin { public static void main(String[] args) throws Exception {  String docPath = "./Worddocument.docx";  String pdfPath = "./Worddocument.pdf";  InputStream in = new FileInputStream(new File(docPath));  XWPFdocument document = new XWPFdocument(in);  PdfOptions options = PdfOptions.create();  OutputStream out = new FileOutputStream(new File(pdfPath));  PdfConverter.getInstance().convert(document, out, options);  document.close();  out.close(); }}

2018年10月:此代码可使用

apache poi 3.17
apache poi 4.0.0
由于到目前为止
apachepoi
尚未考虑到更改,因此无法使用
fr.opensagres.poi.xwpf.converter


2019年2月:对我的作品现在使用的最新

apachepoi
版本
4.0.1
和最新版本
2.0.2
的fr.opensagres.poi.xwpf.converter.core和配偶。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/486751.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号