Contact Us 1-800-596-4880

Finding Information in a PDF

First, you need to find the order ID in the PDF.

As you can see in the image of the order confirmation letter, the order ID is always listed in a table next to the entry 'Order ID'. You can use this information to implement the workflow that contains the following steps:

  1. Copy the content of the order confirmation to a text file.

  2. Read the text file line by line to find the one containing the order ID.

  3. Check if the order ID is found.

  4. Cut out the order ID from the text and store it in an activity parameter.

The Workflow contains the steps in the form of action steps. Some of the action steps are nested.

1. Copying Text From a PDF to a Text File

To open the PDF, you use the Read PDF file action step. Then, you use the returned ReadText as input for the Write to Text File to save the content as a text file on your computer.

An out-filled pin symbol next to the input field shows that the variable is mapped to the text extracted from the PDF in a previous action step.

The following image shows the result of storing the text content. Each line of the PDF has a corresponding line in the text file. Images are omitted.

2. Looping Over All Lines of a Text File

To loop over all lines of the text file, you first need to count the number of lines by reading the entire file using the action step Read from Text File. You use the returned line count as the maximum value for the iteration counter. The counter also functions as the number of the line to read with Read from Text File in each iteration.

3. Checking a Case and Catching Errors

Because you don’t know which line contains the order ID, you use Select Case to differentiate between the two possibilities. If you find the order ID, you copy it from the text and store it in the activity parameter order_id. If you didn’t, which happens in each other line, you still want to complete the loop and the workflow and use Force OK State to avoid returning an error.

The criteria for deciding whether you found the order ID is that the string Order ID is part of the current line.

To add a case, you must first pin the compare value to the action step.

4. Retrieving a Substring and Saving It to a Variable

Because you know that the order ID is written after the text Order ID, you can remove these first nine characters from the current line (which contains the substring Order ID) by using the Trim left (remove first characters) operations of the String Operations action step. The rest of the string is the order ID. You store it in the Activity Parameter with the same name by using the result of the string operation as a Pin Variable in the Set Variable action step.