private static void pdfToWord() {
    File file = new File("F:/使用Acrobat制作PDF模板说明.pdf");
    PDDocument doc = null;
    try {
        doc = PDDocument.load(file);
    } catch (IOException e) {
        e.printStackTrace();
    }
    int pagenumber=doc.getNumberOfPages();//获取总页数
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream("F:/使用Acrobat制作PDF模板说明.doc");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    Writer writer = null;
    try {
        writer = new OutputStreamWriter(fos,"UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    PDFTextStripper stripper = null;
    try {
        stripper = new PDFTextStripper();
    } catch (IOException e) {
        e.printStackTrace();
    }
    stripper.setSortByPosition(true);//排序
    stripper.setStartPage(1);//设置转换的开始页
    stripper.setEndPage(pagenumber);//设置转换的结束页
    try {
        stripper.writeText(doc,writer);
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        writer.close();
        doc.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

 

版权声明:本文为gjq1126-web原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/gjq1126-web/p/11207328.html