zoukankan      html  css  js  c++  java
  • 读取pdf文档里面的文字到本地文档

    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();
        }
    }
  • 相关阅读:
    自定义博客园代码格式
    metaWeblog Test
    STM32 USB复合设备编写
    C数组下标越界
    使用powershell批量修改文本为utf8
    在QtCreator中使用doxygen
    29.内存的基础知识
    28.时钟初始化
    27.点亮led的操作
    26.核心初始化之关闭MMU和cache
  • 原文地址:https://www.cnblogs.com/gjq1126-web/p/11207328.html
Copyright © 2011-2022 走看看