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:

Compiling pdf form

Download the example file

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:

*** Settings *** Library RPA.PDF *** Tasks *** Fill a PDF containing a form and save a copy Open Pdf RobotSpareBin_repair_form.pdf Set Field Value Your name John Doe Set Field Value Warranty /Yes Set Field Value Robot model name Robositter Set Field Value Describe the problem The Robot does not want to start anymore! Save Field Values output_path=Filled_In_PDF.pdf
  • We are adding the RPA.PDF library in the settings section.

    Note: make sure you are using rpaframework version 22.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:

PDF file with filled-in 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:

Naming PDF form fields correctly

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:

Inspecting Fields with adobe Acrobat

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:

*** Settings *** Library RPA.PDF *** Tasks *** Log the list of fields contained in a pdf file Open Pdf RobotSpareBin_repair_form.pdf ${fields}= Get Input Fields Log ${fields}

You can then see the list of fields in the log:

Viewing the list of fields in the log

Last edit: May 17, 2022