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:
-
Copy the content of the order confirmation to a text file.
-
Read the text file line by line to find the one containing the order ID.
-
Check if the order ID is found.
-
Cut out the order ID from the text and store it in an activity parameter.
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.
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.
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.