Java 将Word文档转换为.pdf
我无法逐页阅读Microsoft Word并将其写入PDF文件。 我有ApachePOIJAR3.15和iTextJAR5.0.6。在ApachePOI中,我有5个jar,即poi-3.14.jar、poi-ooxml-3.14.jar、poi-ooxml-schemas-3.14.jar、XmlBeans 2.6.0.jar.poi Scratchpad 3.14.jar。我的代码如下所示Java 将Word文档转换为.pdf,java,apache-poi,Java,Apache Poi,我无法逐页阅读Microsoft Word并将其写入PDF文件。 我有ApachePOIJAR3.15和iTextJAR5.0.6。在ApachePOI中,我有5个jar,即poi-3.14.jar、poi-ooxml-3.14.jar、poi-ooxml-schemas-3.14.jar、XmlBeans 2.6.0.jar.poi Scratchpad 3.14.jar。我的代码如下所示 public class Script
public class Script
{
public void WordToPdf()
{
POIFSFileSystem fs = null;
Document document = new Document();
try
{
System.out.println("Starting the test");
fs = new POIFSFileSystem(new FileInputStream("C:\\Users\\admin\\Desktop\\Srieedher.doc"));
HWPFDocument doc = new HWPFDocument(fs);
WordExtractor we = new WordExtractor(doc);
OutputStream file = new FileOutputStream(new File("C:\\Users\\admin\\Desktop\\test.pdf"));
PdfWriter writer = PdfWriter.getInstance(document, file);
}
catch (Exception e) {
System.out.println("Exception during test");
e.printStackTrace();
}
finally
{
document.close();
}
}
public static void main(String args[])
{
Script1 s=new Script();
s1.WordToPdf();
}
}
通过题为“Java编程概念”的问题和缩进不好的代码并不能帮助你得到问题的答案-你能编辑这个问题使其更容易回答吗?你到底想要什么细节Jerrybibo“我无法一页一页地阅读Microsoft Word并将其写入PDF文件。”具体如何?您收到了什么错误消息?还是没有结果?请给我们您当前的输出和该计划的预期输出。Jerry bibo-我正在获取输出。在MicrosoftWord文件中,我提供了3页内容,但当我将所有内容写入PDFfile时,所有内容仅出现在第一页。我希望Microsoft Word的第1页可以读写到Pdf的第1页。当我阅读MS word的第二页时,同样的内容应该写入PDF文件。POI没有文本页面的概念。这取决于纸张的大小、字体大小、行距等,因此您无法在POI中读取一页文本。您可以从文档中提取文本,但必须自己将其呈现到页面中。POI对此没有帮助。