下载iTextSharp的dll,链接:

http://cdnetworks-kr-2.dl.sourceforge.net/project/itextsharp/itextsharp/iTextSharp-5.0.4/itextsharp-5.0.4-dll.zip

示例代码
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;

namespace ReadPdfDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = GetAllText(@"C:\Users\dc\Desktop\20101098504717.pdf");
        }

        static public string GetAllText(string filePath)
        {
            string text = string.Empty;
            PdfReader reader = new PdfReader(filePath);
            for (int i = 1; i <= reader.NumberOfPages; i++)
            {
                text += GetTextFromPage(reader, i);
            }
            return text;
        }

        static public string GetTextFromPage(PdfReader reader, int pageNum)
        {
            ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
            return PdfTextExtractor.GetTextFromPage(reader, pageNum, strategy);
        }
    }
}
posted on 2010-10-11 12:57  MainTao  阅读(2164)  评论(2编辑  收藏  举报