下载iTextSharp的dll,链接:
示例代码
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);
}
}
}
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);
}
}
}