Click here to Skip to main content
15,881,833 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
C#
using iTextSharp.text.pdf.parser;



Code as Follows:
C#
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();
}
Posted
Updated 13-Aug-14 21:36pm
v2
Comments
Oshtri Deka 14-Aug-14 2:21am    
You have posted similar question only minutes ago!
Maciej Los 14-Aug-14 2:39am    
Please, report it (via using red flag).
Oshtri Deka 14-Aug-14 3:24am    
My bad, questions sound similar, but now I think they are not.
Though both are equally bad!

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900