admin管理员组

文章数量:1316532

I have tried this

string text = "";

using (PdfReader pdfReader = new PdfReader(dlg.FileName))
{

    for (int page = 1; page <= pdfReader.NumberOfPages; page++)
    {
        text = PdfTextExtractor.GetTextFromPage(pdfReader, page);
    }
}
text = text.Replace("\n", "\r\n");

which gave me this result

"AI(240)10575323190069
AI(13)240215
24-02-15 (YY-MM-DD)
PI-734875-1
19006
© Inter IKEA Systems
B.V. 2021
105.753.23
Made in Pakistan"

it just misses "2407" that is written in most right side of the PDF, as seen below. Is there a way that I can read that from my PDF?

I am expecting to read rotated text on the right side of the document along with all.

This is the content of my PDF file:

I have tried this

string text = "";

using (PdfReader pdfReader = new PdfReader(dlg.FileName))
{

    for (int page = 1; page <= pdfReader.NumberOfPages; page++)
    {
        text = PdfTextExtractor.GetTextFromPage(pdfReader, page);
    }
}
text = text.Replace("\n", "\r\n");

which gave me this result

"AI(240)10575323190069
AI(13)240215
24-02-15 (YY-MM-DD)
PI-734875-1
19006
© Inter IKEA Systems
B.V. 2021
105.753.23
Made in Pakistan"

it just misses "2407" that is written in most right side of the PDF, as seen below. Is there a way that I can read that from my PDF?

I am expecting to read rotated text on the right side of the document along with all.

This is the content of my PDF file:

Share Improve this question edited Jan 30 at 9:29 DarkBee 15.6k8 gold badges72 silver badges117 bronze badges asked Jan 30 at 9:24 SYED RASHIDSYED RASHID 112 bronze badges 6
  • 1 PDF isn't an editable document, it's just print instructions that can appear in any order. You're just lucky the letters M a d e ` ` i n etc were next to each other (in the file, not the printed page) and so were treated as consecutive text. Libraries have to guess whether the positioning and rendering instructions they find are text or not. – Panagiotis Kanavos Commented Jan 30 at 9:28
  • 2 Check if it's really a text. I don't think text rotation matter when extracting text from page. – Sinatr Commented Jan 30 at 9:29
  • when i open it in adobe pdf reader and select that "2407" it is not treated as text but an image. – SYED RASHID Commented Jan 30 at 9:32
  • The "easier" strings 19006 and 105.754.23 weren't extracted either. It may not be possible to extract them (or the "rotated" text) or you may have to use a different TextExtractionStrategy – Panagiotis Kanavos Commented Jan 30 at 9:35
  • 1 but an image. you can't read it as text then. You'll have to use an OCR library. Which, by the way, is quite often the best option with PDFs. iText does that with its pdfOCR product, which uses the Tesseract library underneath. – Panagiotis Kanavos Commented Jan 30 at 9:38
 |  Show 1 more comment

1 Answer 1

Reset to default 0

OCR is often problematic especially for numbers so if you have 95 % correct it is good and then you only need to correct or add the last 5%.

Avoid OCR for numbers as often they will be missing or incorrect, and the large 105.753.23 is often not recognised in a page of other text.

Here I used the online Demo of SautinSoft and can get that 2407 but for every other image it may not be the case. OCR is never "Guaranteed" nor should be.

You can get the same (or better quality) simply by asking tesseract to generate both text and PDF at the same time like here.

Note again that both the 105.753.23 and 19006 have been misread as MAA ATT.

本文标签: cHow to read rotated textStack Overflow