admin管理员组文章数量:1605131
java把pdf转换为word格式
第一步 导包
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox-tools</artifactId>
<version>2.0.11</version>
</dependency>
第二步 写代码块
public static void convertText(String pdfPath){
PDDocument doc = null;
OutputStream fos = null;
Writer writer = null;
PDFTextStripper stripper = null;
try {
doc = PDDocument.load(new File(pdfPath));
fos = new FileOutputStream(pdfPath.substring(0, pdfPath.indexOf(".")) + ".doc");
writer = new OutputStreamWriter(fos, "UTF-8");
stripper = new PDFTextStripper();
int pageNumber = doc.getNumberOfPages();
stripper.setSortByPosition(true);
stripper.setStartPage(1);
stripper.setEndPage(pageNumber);
stripper.writeText(doc, writer);
writer.close();
doc.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("end..");
}
public static void main(String[] args) {
convertText("D:\\BaiduNetdiskDownload\\javaee开发的颠覆者springboot实战.pdf");
}
这样就简单又轻松的转变了pdf到word文件
版权声明:本文标题:java把pdf转换为word格式 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1728480065a1160012.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论