Find a word in PDF, either continue or end process

I am trying to find a word in a PDF (the word is Previous) and if that word exists, continue the process. If that word does not exist, end the process. I have an activity to open up the PDF and my though is, use an assign to find the word, then use an IF and create a condition stating If the variable is true (meaning the word exists) then use continue activity, else send out an email alert and terminate workflow.

I’m not sure how to do this the right way or if this is the right way to handle.

Hello @atarantino !

In my opinion, the best way to fulfill your needs, would be either using UiPath PDF activities, (if the PDF is native), or OCR (if the PDF is a scanned file)

  • Native: (Means that the text is selectable in PDF)

Package required for both cases:

image

Activities to use:

image

  • Yellow = Native
  • Green = Scanned

Both of them will give a string as an output.

With that string you can build the condition directly in the “IF” activity:

IF Condition: var_StringPDFOutput.Contains(“Previous”) → This will give either True or False depending on if the word exists in the PDF or not.

This is perfect thank you.

Since you seem far more advanced than myself, in the else i put a send email (which worked) and after that i want to end my entire process.

When i add “Terminate workflow” it terminates but it gives me a pop up of an error. How do i stop that or is there a better way to cancel the workflow?

image

Put this in a flowchart instead of a sequence. In the else assign an integer to something like success|1 or something like that and take the send email message out of the else. Then use a flow decision with a condition if success = 1 then send an email. The process will stop after that.

If you are using a state machine then you can add a throw with a new business rule exception with your message and have a business rule exception isNot Nothing path to the end state and your automation will stop

Hey again @atarantino , glad it did help!

What I’d do in this situation, and assuming you’re not using the ReFramework, but a Sequence or a flowchart instead, would be the following:

Instead of Terminate Workflow, which will give you the Popup, I’d use a “Throw” activity, with for example, a BusinessRuleException:

If the bot reaches this path, it will skip the rest of the “Sequence” or “Flowchart” and it will jump to the “Catch” of type “BusinessRuleException”. Therefore reaching the end and finishing:

On the catch I’d put something in order to identify why it did stop (you can use a custom message, or exception.message)

image

this way, if the bot goes on the “Else” side of the execution, the output will be the following. But it won’t give any popup:

image

Attaching a Dummy sequence I built to take the screenshots, so you can play with it and understand the logic :slight_smile:

DemoEndTryCatch.zip (60.4 KB)

  • Please note that if you run on Debug, to reach the “catch” you’ll need to click several times the Continue button. Running normally will not trigger the stops on the code :slight_smile:

Hope this helps!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.