How to fill PDF forms with RPA Framework
PDF files can contain forms that users can fill using a desktop program like Acrobat Reader or Preview on macOS. Using the RPA.PDF library, you can automate this easily! Let's see how.
Our favorite fictional company, RobotSpareBin Industries has a PDF form that customers can use if (when, more likely) their robots break down and need repairs. Here's how it looks like:
If you are curious, you can learn more about RobotSpareBin Industries Inc. in our Beginners' course, and even more in the follow-up course, Build a robot! Completing the courses will grant you Robocorp certificates!
Filling a PDF form with RPA Framework
Here's how we can fill the form in the PDF file with a software robot:
- We are adding the
RPA.PDF
library in the settings section.Note: make sure you are using
rpaframework
version22.0.0
or greater. - We are opening the file with the
Open Pdf
keyword (the file in our example is in the same directory as the.robot
script). - Using the
Set Field Value
keyword, we are referring to each field by its name and passing the value we want to fill. - We then save the filled PDF file with the
Save Field Values
keyword!
Our saved file will now have the filled form:
How do I know the names of the fields in my PDF form?
To target a field, you need to know its name. This is not always easy, but there are solutions!
In our test example, each field has the same name as the associated label, so it's pretty straightforward:
But this is not always the case...
Using Adobe Acrobat
If you have Adobe Acrobat available (note, not Adobe Acrobat Reader), you can open the PDF file and inspect each field, getting to the Name
property:
That is the value you will want to give as an argument with the Set Field Value
keyword.
Using the Get Input Fields
keyword
If you do not have Adobe Acrobat available, you can list the fields that your PDF document contains using the Get Input Fields
keyword like this:
You can then see the list of fields in the log: