Note:- This article is mainly intended to read content from
a PDF file and convert that into a string using C#.
The following steps will guide you to read content from a PDF file:
The following steps will guide you to read content from a PDF file:
- To start with this, you need to download itextsharp-all-5.2.1, which can be download from here.
- Extract the whole archive (inside itextsharp-all-5.2.1 folder also) to your local directory.
- Create a new Console Project.
- Add itextsharp-all-5.2.1.dll as reference.
- the following Code is :
-
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using iTextSharp.text.pdf;using iTextSharp.text.pdf.parser;namespace pdf2Text2{public class Program{static string pdfFile = @"D:\oshAden.pdf";static void Main(string[] args){ExtractTextFromPDFPage(pdfFile, 1);}public static void ExtractTextFromPDFPage(string pdfFile, int pageNumber){PdfReader reader = new PdfReader(pdfFile);int pageNum = reader.NumberOfPages;StringBuilder sb= new StringBuilder ();for (int i = 1; i <= pageNum; i++){sb.AppendLine(PdfTextExtractor.GetTextFromPage(reader, i));}try { reader.Close(); }catch { }Console.WriteLine(sb);Console.ReadLine();}}}Download this Project : Click @ meEnjoy.
0 comments:
Post a Comment