In this tutorial, I'm going to be showing you the different ways you can scrape data from a PDF documents
using optical character recognition.
So the most common way is to use the kit OCR text activity over here.
So under UI automation, OCR screen scraping, we have to get OCR text activity.
So this is what you want to use when you want to scrape a certain piece of text from a PDF.
If you want to scrape all the text from the entire PDF, you'd have to use something else.
So you'd have to install this package.
So you would have to come to manage packages over here and you can come to all packages and you can
search for PDF over here.
You'll see a UI poster PDF DOT activities and you can install this.
Okay, then click save to make sure that the installation completes.
It'll download the dependencies.
Great.
So now the PDF activities should have been added to your activities panel on the left, you see, if
I search for PDF, you'll see here there is now a read PDF text and a read PDF with OCR.
So this is the one we're looking for.
What this does, it read all the characters from a specified PDF and it'll output everything that it
reads as text.
So let's try and run it here just so I can show you how it works so we can drag this in.
And you can see here it asks you for a file name and then it asks for an OCR engine.
So the filename would simply be the PDF.
So you can just type in PDF.
All right.
You can see it's probably requires a string over here.
Let's just come here.
Yes, it requires a string.
So you can say Dotto String can see there.
It's a string.
That's how I knew that.
Click OK, click away.
So there's still an area that's probably because we haven't added our OCR engine yet.
Let's just see what it says.
Yes, it says no OCR engine assigned so you can close this.
We can type in OCR and there should be a section with OCR engines here and a UI automation OCR engine.
These are the different OCR engines which you could use, which will actually do the converting from
image into text.
So here they are, four listed ones.
There's Ebbe, there's Google, there's Microsoft and there's Tesseract.
What tends to work?
Well, when you use it, when you're scraping components of a PDF would be the Google OCR.
But when you're scraping an entire PDF, usually from my experience, I find the Microsoft OCR works
better.
All right.
So you can experiment with all the different ones depending on your PDF, because sometimes one might
work better over another.
So we can use Microsoft OCR over here and we'll drag that into.
What we can then do is you can click on our read PDF with OCR and over here you can see there's a text
output so we can create a variable which will then store that text.
So I'll just say control.
Okay, to create a variable and I'll call it
OCR.
Output's.
Just like that, OK, we're not going to be keeping this, this is just for demonstration purposes of
they use a right line activity.
To write everything that read the output panel.
So over here, we want to write our OCR output and that is all.
So I'm just going to clear our output panel.
I'll make sure there's no PDF open and we can run this and see what happens.
So now it's opened all three and it should have scraped all the data and here you can see.
There you go.
You'll notice that it spits out the titles first, such as product name, trademark middle name, that
is all of these here on the left hand side, product name, trademark middle name, et cetera.
And on the right hand side, it's, for example, GRV Sports is listed just below that.
It should be there, GRV, Sports, etc. and then it has all the values just below that.
So it doesn't spit it out in a nice formatted order, unfortunately, but it does scrape all the data
from the PDF.
An application I could think of for this would be something like where you want to search all the text
inside a scanned PDF document and you want to search for a certain term.
If that term exists, then you can then, for example, save that PDF into a certain folder.
And if that term doesn't exist, then it saves that PDF into a different folder or something like that.
So the way you could go about doing that is you could use something like a if statement she could use.
And if you can search for the text, which it outputs it, in our case, it was OCR output.
So you can select OCR output, you can say DOT contains and then you can search for a certain term.
For example, let's say you're looking for all the invoices which have the product GRV eSport in it.
Then what you do is you add simply right here, g r v dash e dash sports.
Then from there you can assign certain sequences to do whatever you want.
If it does contain that, do this, if it doesn't contain that, do that, etc..
All right.
So that is just a quick summary of how to use the read PDF with OCR activity.
In the next video, I'll be showing you how to scrape a certain elements from a PDF using OCR.