如何使用POI将.doc / .docx转换为java中的pdf ..?

如何将ms-document转换为PDF,有什么例子请与我分享..谢谢。

如果您需要使用POI我想你应该看看org.apache.poi.hwpf.converter
我从来没有试过这个,但我想这至少值得一试。 您似乎可以使用WordToFoConverterWordToFoConverter转换为FO文件( 此处为示例 )。
从那里你可以使用apach FOP将FO文件转换为这样的PDF:

 // Step 1: Construct a FopFactory // (reuse if you plan to render multiple documents!) FopFactory fopFactory = FopFactory.newInstance(); // Step 2: Set up output stream. // Note: Using BufferedOutputStream for performance reasons (helpful with FileOutputStreams). OutputStream out = new BufferedOutputStream(new FileOutputStream(new File("C:/Temp/myfile.pdf"))); try { // Step 3: Construct fop with desired output format Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out); // Step 4: Setup JAXP using identity transformer TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); // identity transformer // Step 5: Setup input and output for XSLT transformation // Setup input stream Source src = new StreamSource(new File("C:/Temp/myfile.fo")); // Resulting SAX events (the generated FO) must be piped through to FOP Result res = new SAXResult(fop.getDefaultHandler()); // Step 6: Start XSLT transformation and FOP processing transformer.transform(src, res); } finally { //Clean-up out.close(); } 

此代码取自https://xmlgraphics.apache.org/fop/0.95/embedding.html,如果您想了解有关此主题的更多信息。