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!
Here's how we can fill the form in the PDF file with a software robot:
- We are adding the
RPA.PDFlibrary in the settings section.
Note: make sure you are using
- We are opening the file with the
Open Pdfkeyword (the file in our example is in the same directory as the
- Using the
Set Field Valuekeyword, 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 Valueskeyword!
Our saved file will now have the filled 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
That is the value you will want to give as an argument with the
Set Field Value keyword.
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: