开发者

how to read pdf file through C#?

i have pdf file and i 开发者_JAVA技巧need to read the text and to insert to any val.

how do to it with C# (winform) ?

thank's in advance


I'd suggest iTextSharp there's some sample code here http://www.codeproject.com/KB/string/pdf2text.aspx


You will need a PDF library of some sort. PDFSharp can reportedly do this - create and edit pdf files.


In order to read the contents of a pdf file, you will need a 3rd party dll file like the above mentioned ITextSharp or PDFSharp. But if you only want to display the pdf file to the user of the application, then you can use web browser control. provided that you have adobe acrobat installed.


As a previous User said, try it with iTextSharp. For this, I read out the whole PDF and post the whole PDF and return it, for example to put it into a textbox:

public string ReadPdfFile(object Filename)
        {
            PdfReader reader = new PdfReader((string)Filename);
            string strText = string.Empty;

            for (int page = 1; page <= reader.NumberOfPages; page++)
            {
                ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy();
                PdfReader reader = new PdfReader((string)Filename);
                String s = PdfTextExtractor.GetTextFromPage(reader, page, its);

                s = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(s)));
                strText = strText + s;
                reader.Close();
            }
            return strText;
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜