Java 如何使用POI将HWPF文档转换为inputstream

Java 如何使用POI将HWPF文档转换为inputstream,java,Java,我必须更改文档word中的文本并转换为pdf。 我已经更改了文本,但IDK,如何将HWPF文档转换为pdf 在调用XWPFDocument文档中=新的XWPFDocument(is);我得到异常io.IOException:流已关闭 String inputFilename = "/root/GeneratorUmow/web/WEB-INF/umowy/kkb/wniosekkkb.doc"; POIFSFileSystem fs = null; is = new FileInputStrea

我必须更改文档word中的文本并转换为pdf。 我已经更改了文本,但IDK,如何将HWPF文档转换为pdf

在调用XWPFDocument文档中=新的XWPFDocument(is);我得到异常io.IOException:流已关闭

String inputFilename = "/root/GeneratorUmow/web/WEB-INF/umowy/kkb/wniosekkkb.doc";
POIFSFileSystem fs = null;
is = new FileInputStream(inputFilename);
fs = new POIFSFileSystem(is);
HWPFDocument doc = new HWPFDocument(fs);
Range range = doc.getRange();
range.replaceText("nazwaFirmy", "KAKAOWY SZATAN");
//conversion na pdf
XWPFDocument document = new XWPFDocument(is);
PdfOptions options = PdfOptions.create().fontEncoding("windows-1250");
OutputStream out = new FileOutputStream(new File("kakaowyszal.pdf"));
PdfConverter.getInstance().convert(document, out, options);

我将非常感谢您的帮助。

我知道这个问题很老,但有一种简单的方法可以将XWPFDocument“转换”为InputStream。万一有人需要它

ByteArrayOutputStream b = new ByteArrayOutputStream();
doc.write(b); // doc should be a XWPFDocument 
InputStream inputStream = new ByteArrayInputStream(b.toByteArray());

我知道这个问题由来已久,但有一种简单的方法可以将XWPFDocument“转换”为InputStream。万一有人需要它

ByteArrayOutputStream b = new ByteArrayOutputStream();
doc.write(b); // doc should be a XWPFDocument 
InputStream inputStream = new ByteArrayInputStream(b.toByteArray());

哪个jar文件用于PdfOptions和PdfConverter?org.apache.poi.xwpf.converter.core-1.0.0,org.apache.poi.xwpf.converter.pdf-1.0.0。你知道吗?你已经将ooxml库添加到你的类路径中了吗?是的,我附加了poi-ooxml-3.5-FINALi认为,这个异常不是缺少库的错误,而是POIFSFileSystem可能已经关闭了inputStream连接。哪个jar文件用于PdfOptions和PdfConverter?org.apache.poi.xwpf.converter.core-1.0.0,org.apache.poi.xwpf.converter.pdf-1.0.0。你知道吗?你已经将ooxml库添加到你的类路径中了吗?是的,我附加了poi-ooxml-3.5-FINALi,我认为,这个异常不是缺少库的错,但是POIFSFileSystem可能已经关闭了inputStream连接。