Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

'PdfTextExtractor' does not contain definition for 'GetTextFromPage'

‘PdfTextExtractor’ does not contain definition for ‘GetTextFromPage’, it throws Compiler Error CS0117

This is my code, which I have coppied just to check how does iText7 work:

using System;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas.Parser.Listener;

namespace PdfParser
{
    public static class PdfTextExtractor
    {
        public static void ExtractTextFromPDF(string filePath)
        {
            PdfReader pdfReader = new PdfReader(filePath);
            PdfDocument pdfDoc = new PdfDocument(pdfReader);

            for (int page = 1; page <= pdfDoc.GetNumberOfPages(); page++)
            {
                ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();

                // the line below throws the exception
                string pageContent = PdfTextExtractor.GetTextFromPage(pdfDoc.GetPage(page), strategy);
            }

            pdfDoc.Close();
            pdfReader.Close();
        }
    }
}

I tried using iTextCsharp, but there was writen that iText7 is a new version.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am working on "Console Application", maybe this is the problem? Should I use another framework?

>Solution :

The problem is that your class is also called PdfTextExtractor. Please rename your static class and the issue will be solved.

For future issues, you can jump to the reference (via F12 or similar, depending on your IDE/Shorctus) and check where it directs you.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading