源码

String pdfFile = “C:\Users\15105\Downloads\” + annex.getFileName();//pdf路径
 PDDocument doc = PDDocument.load(new File(pdfFile));
 int pagenumber = doc.getNumberOfPages();
 pdfFile = pdfFile.substring(0, pdfFile.lastIndexOf("."));
 String fileName = pdfFile + “.doc”;//word路径
 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成功!”);

所需jar包


org.apache.pdfbox

pdfbox-tools

2.0.11



org.apache.pdfbox

fontbox

2.0.11



com.levigo.jbig2

levigo-jbig2-imageio

2.0


java解析pdf转换成jsp java实现pdf转word_System