---
schema_version: "1"
id: 6e3ab0b89d3b5d7b2d1dd6ccb710de8f80d8b246c61dcacd1aa6cfa368f13c78
title: Finding Information in a PDF
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/rpa-home/automation-usecase-legacysystemdataextraction-extractfrompdf.md
canonical_url: https://docs.mulesoft.com/rpa-home/automation-usecase-legacysystemdataextraction-extractfrompdf
source_site: docs.mulesoft.com
content_type: documentation
content_hash: fa91c490390944cb5ed3293036ec2c57640a33b10ee04b4498c381aa937ee72f
description: MuleSoft Documentation Site
latest: true
---
---
product: RPA
---

# Finding Information in a PDF

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

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

As you can see in
[the image of the order confirmation letter](https://docs.mulesoft.com/rpa-home/automation-usecase-legacysystemdataextraction#confirmationletter-image),
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.](/mulesoft/current/en-us/rpa-home/_images/usecase-legacysystem-extractformpdf-workflow-overview.png)

## 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.](/mulesoft/current/en-us/rpa-home/_images/usecase-legacysystem-extractformpdf-workflow-pdftotxt.png)

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.

![](/mulesoft/current/en-us/rpa-home/_images/extractorderid-workflow-resultpdftotxt.png)

## 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.

![](/mulesoft/current/en-us/rpa-home/_images/usecase-legacysystem-extractformpdf-workflow-loopovertextfilelines.png)

## 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.](/mulesoft/current/en-us/rpa-home/_images/usecase-legacysystem-extractformpdf-workflow-checkcaseandproceed.png)

## 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.

![](/mulesoft/current/en-us/rpa-home/_images/usecase-legacysystem-extractformpdf-workflow-cutsubtringoutoftext.png)

## See Also

- [RPA Builder Action Step: Read PDF File](https://docs.mulesoft.com/rpa-builder/latest/toolbox-file-operations-read-pdf-file)

- [RPA Builder Action Step: Write to Text File](https://docs.mulesoft.com/rpa-builder/latest/toolbox-file-operations-write-to-text-file)

- [RPA Builder Action Step: Read from Text File](https://docs.mulesoft.com/rpa-builder/latest/toolbox-file-operations-read-from-text-file)

- [RPA Builder Action Step: Select Case](https://docs.mulesoft.com/rpa-builder/latest/toolbox-flow-control-select-case)

- [RPA Builder Action Step: Force OK State](https://docs.mulesoft.com/rpa-builder/latest/toolbox-flow-control-force-ok-state)

- [RPA Builder Action Step: String Operations](https://docs.mulesoft.com/rpa-builder/latest/toolbox-variable-handling-string-operations)

- [RPA Builder Action Step: Set Variable](https://docs.mulesoft.com/rpa-builder/latest/toolbox-variable-handling-set-variable)

[Usecase: Extract Data from a Legacy System](https://docs.mulesoft.com/rpa-home/automation-usecase-legacysystemdataextraction)
[Interacting with a Screen of a Legacy Application](https://docs.mulesoft.com/rpa-home/automation-usecase-legacysystemdataextraction-extractfromscreen)
