JAVA实现pdf转换word(其中的图片无法识别)
1.在pom.xml中引入jar包;
org.apache.pdfbox pdfbox 2.0.24
2.实现下面的方法;
public static void main(String[] args)
{try{String pdfFile = "C:\\Users\\zengh\\Desktop\\简历.pdf";PDDocument doc = PDDocument.load(new File(pdfFile));int pagenumber = doc.getNumberOfPages();pdfFile = pdfFile.substring(0, pdfFile.lastIndexOf("."));String fileName = pdfFile + ".doc";File file = new File(fileName);if (!file.exists()){file.createNewFile();}FileOutputStream fos = new FileOutputStream(fileName);Writer writer = new OutputStreamWriter(fos, "UTF-8");PDFTextStripper stripper = new PDFTextStripper();stripper.setSortByPosition(true);// 排序stripper.setStartPage(1);// 设置转换的开始页stripper.setEndPage(pagenumber);// 设置转换的结束页stripper.writeText(doc, writer);writer.close();doc.close();System.out.println("pdf转换word成功!");}catch (IOException e){e.printStackTrace();}
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
