Click here to Skip to main content
15,887,302 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have some PDFs of newspaper clippings (when opened in Chrome, the text in them is fully searchable and doesn't look scanned). However, when do I use itext7 I'm only getting the text above the dotted line (see link Untitled hosted at ImgBB — ImgBB[^]) and the footer.

What I have tried:

C#
using (MemoryStream memoryStream = new MemoryStream(pdfBytes))
{
    // Create reader from bytes
    using (PdfReader pdfReader = new PdfReader(memoryStream))
    {
        PdfDocument srcDoc = new PdfDocument(pdfReader);
        for (int p = 1; p <= srcDoc.GetNumberOfPages(); p++)
        {
            try
            {
                var page = srcDoc.GetPage(p);
                var strategy = new SimpleTextExtractionStrategy();
                var currentText = 
                 PdfTextExtractor.GetTextFromPage(page, strategy);
Posted
Updated 13-Sep-23 6:45am
v5
Comments
Richard MacCutchan 30-Aug-23 3:43am    
Most likely because the content of the PDF is a scanned image and not text. You can easily check this by examining the actual data in the file.

1 solution

Based on your screenshot, the text beneath the dotted line is very clearly a scanned image of a newspaper cutting.

Chrome is most likely using OCR to extract the text from the image. iText does not do that for you out of the box. You'll need to use their add-on pdfOCR[^] for that.
 
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