在.Net中阅读PDF文档 [英] Reading PDF documents in .Net

查看:26
本文介绍了在.Net中阅读PDF文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个开源库可以帮助我在 .NET/C# 中阅读/解析 PDF 文档?

Is there an open source library that will help me with reading/parsing PDF documents in .NET/C#?

推荐答案

自从上次回答这个问题是在 2008 年以来,iTextSharp 已经显着改进了他们的 api.如果您从 http://sourceforge.net/projects/itextsharp/ 下载他们的 api 的最新版本,您可以使用以下代码片段将 pdf 中的所有文本提取为字符串.

Since this question was last answered in 2008, iTextSharp has improved their api dramatically. If you download the latest version of their api from http://sourceforge.net/projects/itextsharp/, you can use the following snippet of code to extract all text from a pdf into a string.

using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;

namespace PdfParser
{
    public static class PdfTextExtractor
    {
        public static string pdfText(string path)
        {
            PdfReader reader = new PdfReader(path);
            string text = string.Empty;
            for(int page = 1; page <= reader.NumberOfPages; page++)
            {
                text += PdfTextExtractor.GetTextFromPage(reader,page);
            }
            reader.Close();
            return text;
        }   
    }
}

这篇关于在.Net中阅读PDF文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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