zoukankan      html  css  js  c++  java
  • 将PDF转为TXT文本格式提取中文

     以下的读取方式,针对个别PDF文件会出现读取内容为乱码的现象,如果有高手有其他办法可以解决,就提供下,大家一起学习

    winform代码
    首先要在网上下载:PDFBox

    通过引用两个DLL:
    IKVM.GNU.Classpath.dll
    PDFBox
    -0.7.3.dll

    将两个DLL放在项目的BIN目录下:
    FontBox
    -0.1.0-dev.dll
    IKVM.Runtime.dll

    //引用的空间,由项目饮用的动态DLL后才能使用
    using org.pdfbox.pdmodel;
    using org.pdfbox.util;

    //按钮事件中的代码
    private void button2_Click(object sender, System.EventArgs e)
    {


    PDDocument txtTmp 
    = PDDocument.load(文件物理路径)
                    PDFTextStripper pdfStripper 
    = new PDFTextStripper();
                    textBox1.Text 
    = pdfStripper.getText(txtTmp);
                    textBox1.Text 
    += textBox1.Text.Length;

    /* 如下的以后使用参考
    DialogResult dr = folderDialog.ShowDialog();
                if(dr != DialogResult.OK)
                {
                    return;
                }
                //选择文件的路径
                folderPath  = folderDialog.SelectedPath;

    DirectoryInfo dirPDF = new DirectoryInfo(folderPath);
                if(!dirPDF.Exists)
                {
                    MessageBox.Show("您录入的文件路径有误,请核实!");
                    return;
                }

                FileInfo[] fileOldSystem = dirPDF.GetFiles("*.pdf");
                if(fileOldSystem.Length == 0)
                {
                    MessageBox.Show("您选择的文件路径下没有PDF文件,请核实!");
                    return;
                }

                foreach(FileInfo file in fileOldSystem)
                {
                    PDDocument txtTmp = PDDocument.load(file.FullName.ToLower());
                    PDFTextStripper pdfStripper = new PDFTextStripper();
                    textBox1.Text = pdfStripper.getText(txtTmp);
                    textBox1.Text += textBox1.Text.Length;

                    StreamWriter sw = File.AppendText(file.FullName.ToLower().Replace(".pdf",".txt"));
                    sw.Write(textBox1.Text);
                    sw.Flush();
                    sw.Close();

                }

    */


    }
  • 相关阅读:
    java 实验五保存网页到本地
    Codeforces Round #485 (Div. 2)F. AND Graph
    算法设计分析实验三——贪心求最小生成树
    D. XOR-pyramid Codeforces Round #483 (Div. 2) dp
    C. Finite or not? Codeforces Round #483 (Div. 2)
    Educational Codeforces Round 44 F. Isomorphic Strings
    Educational Codeforces Round 44 (Rated for Div. 2)+E. Pencils and Boxes+树状数组
    BZOJ 1012 [JSOI2008]最大数maxnumber
    BZOJ 1207 [HNOI2004]打鼹鼠(简单dp)
    POJ 3067 Japan(树状数组求逆序对)
  • 原文地址:https://www.cnblogs.com/hanguoji/p/1641460.html
Copyright © 2011-2022 走看看