How to read .pdf file in C# as a string

 public string ConvertPdfFileInToText(string path)
        {         
           var stream = new FileStream(path, FileMode.OpenOrCreate);
            using (PdfReader reader = new PdfReader(stream))
            {
                StringBuilder text = new StringBuilder();

                for (int i = 1; i <= reader.NumberOfPages; i++)
                {
                    text.Append(PdfTextExtractor.GetTextFromPage(reader, i));
                }
                return text.ToString();
            }
        }

Leave a Reply

Your email address will not be published. Required fields are marked *