Tesseract OCR extracting Nozzle Number incorrectly in UiPath

Hi everyone,

I am using UiPath Community Edition with Read PDF With OCR and Tesseract OCR to extract data from gas-station receipts.

The actual receipt contains:

Nozzle. No : 2

But the OCR output from pdfText is:

Nozzle. Ho 12

Because of this, my Regex extracts 12 instead of the actual nozzle number 2.

I am currently using:

System.Text.RegularExpressions.Regex.Match(pdfText, "(?im)^Nozzle[ \t]*[.:]?[ \t]*No[ \t]*:?[ \t]*(\d+)[ \t]*$").Groups(1).Value.Trim

I have confirmed that the OCR output itself contains Nozzle. Ho 12, so the issue appears to happen during OCR rather than during the Regex extraction.

My question: What is the best way to handle this in UiPath? Should I change the Tesseract OCR settings, preprocess the PDF/image, use another free OCR engine available in Community Edition, or use a different Regex/approach?

I want the bot to reliably extract the actual nozzle number without hardcoding a correction such as changing 12 to 2.

Any suggestions or best practices would be appreciated.


receipt-petrol-1654780371.pdf (105.2 KB)

Hi @Abhinay_Reddy1

Nice process!

The way you can try and resolve this is by doing a few things:

  1. Try each profile setting under the “Profile” option of the Tesseract properties:
  2. Try another OCR engine:
  3. My best advice would be to use some sort of AI if you’re struggling to get consistency. GenerativeAI activities are great and pretty accurate. Or if you’re dealing with a lot of receipts, trying using IXP (Document Understanding) and train a model to read everything off each receipt. But this will consume AI/Platform units depending on which Community plan you’re on. Still worth trying.

Hope this helps :slight_smile:

I think the issue is with the OCR itself, not the Regex. Since Tesseract is reading Nozzle. No : 2 as Nozzle. Ho 12, the Regex is just extracting the wrong value from the OCR result.

I’d try improving the image quality first, like cropping the nozzle section and increasing the resolution/contrast before running Tesseract.

You can also test another OCR engine, such as Microsoft OCR, and compare the results. I wouldn’t hardcode 12 to 2, because that may fail with other receipts.

Hi @Abhinay_Reddy1

Read PDF with OCR with Tesseract OCR will work. Try changing the properties of Tesseract OCR.

Scale: Start from 0 increasing it by 0.5 until 5. In any one of the point, you will be getting the exact text.
Profile: You will have 4 options over there for every scale try changing by 4 options.

If Tesseract OCR doesn’t work for your exact extraction, try using Omni page OCR by downloading UiPath.OmniPage.Activities. This may work for you.

Regards
PS Parvathy

Hi @Abhinay_Reddy1 ,
You can use the steps:

  1. Use a better OCR engine
    • Try Microsoft OCR or OmniPage OCR instead of Tesseract.
    • They generally handle receipts and scanned documents better than Tesseract.
  2. Improve image quality before OCR
    • Convert PDF to a higher resolution image.
    • Apply image preprocessing such as grayscale, contrast enhancement, or noise removal.
    • Better image quality usually improves OCR accuracy significantly.
  3. Use anchor-based extraction
    • After OCR, find the line containing "Nozzle" and extract the value immediately after ":".
    • This is often more reliable than searching the entire text.
  4. Validate against business rules
    • If nozzle numbers are typically single digits , add a validation step.
    • When OCR returns suspicious values like 12 while the receipt layout suggests a single nozzle number, flag it for review instead of hardcoding corrections.
  5. Regex is fine
    • Your current Regex is not causing the error.
    • The root cause is the OCR output itself. Focus on improving OCR quality rather than changing the Regex.

Thanks