如何使用IText库从C#2.0中提取asp.net中PDF文件的文本? [英] How to extract text from PDF file in asp.net with C#2.0 using IText library?

查看:45
本文介绍了如何使用IText库从C#2.0中提取asp.net中PDF文件的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#2.0从asp.net中的PDF文件中提取文本?我添加了itextsharp dll作为参考。但我没有使用 iTextSharp.text.pdf.parser获取命名空间

How to extract text from PDF file in asp.net with C#2.0?I have added itextsharp dll as reference. But I am not getting the namespace

using iTextSharp.text.pdf.parser;







代码如下:




Code as Follows:

using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using System.Text;

public void ReadPdfFile(string fileName)
{
    StringBuilder text = new StringBuilder();

    PdfReader pdfReader = new PdfReader(fileName);

    for (int page = 1; page <= pdfReader.NumberOfPages; page++)
    {
        //ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
        //string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);

        currentText = Encoding.UTF8.GetString(Encoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.UTF8.GetBytes(currentText)));
        text.Append(currentText);
        pdfReader.Close();
     }

     string s = text.ToString();
}

推荐答案

您显然选择了库/工具有问题因此我建议您从制造商的网站下载免费电子书。也许您使用的库版本与您选择的教程中使用的版本不匹配。



阅读这些版本,它不会受到伤害:

使用C#中的iTextSharp创建/读取高级PDF报告

使用iTextSharp创建PDF文档

简单的.Net解决方案
You obviously have problem with chosen library/tool therefore I suggest you to download free eBook from the manufacturer's site. Perhaps there is mismatch between library version you use and version used in tutorial you picked.

Read these as well, it won't hurt:
Create/Read Advance PDF Report using iTextSharp in C#
Creating PDF documents with iTextSharp
Simple .Net Solutions


这篇关于如何使用IText库从C#2.0中提取asp.net中PDF文件的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆