PDF invites creator robot
Get the code and run this example in your favorite editor on our Portal!
This robot will generate a personalized PDF invitation for each participant to an event starting from an Excel file.
This robot will:
- download and collect the data from an Excel file
- process the data into the correct format
- loop through the data and generate a personalized PDF for each event participant using a template into a temporary folder
- collect all generated files into a zip archive in the output folder
- write log files
- clean up after itself by deleting the temporary folder
Robot script
*** Settings ***
Documentation Creates PDF invitations based on Excel data.
Library RPA.Archive
Library RPA.Excel.Files
Library RPA.FileSystem
Library RPA.PDF
*** Variables ***
${EXCEL_FILE_PATH}= ${CURDIR}${/}devdata${/}Data.xlsx
${PDF_TEMP_OUTPUT_DIRECTORY}= ${CURDIR}${/}temp
${PDF_TEMPLATE_PATH}= ${CURDIR}${/}devdata${/}invite.template
*** Tasks ***
Create PDF invitations
Set up directories
${invitations}= Collect invitations from the Excel file
FOR ${invitation} IN @{invitations}
Run Keyword And Continue On Failure
... Create PDF file for invitation
... ${invitation}
END
Create ZIP package from PDF files
[Teardown] Cleanup temporary PDF directory
*** Keywords ***
Set up directories
Create Directory ${PDF_TEMP_OUTPUT_DIRECTORY}
Create Directory ${OUTPUT_DIR}
Collect invitations from the Excel file
Open Workbook ${EXCEL_FILE_PATH}
${invitations}= Read Worksheet header=True
Close Workbook
RETURN ${invitations}
Create PDF file for invitation
[Arguments] ${invitation}
Template Html To Pdf
... ${PDF_TEMPLATE_PATH}
... ${PDF_TEMP_OUTPUT_DIRECTORY}/${invitation["first_name"]}_${invitation["last_name"]}.pdf
... ${invitation}
Create ZIP package from PDF files
${zip_file_name}= Set Variable ${OUTPUT_DIR}/PDFs.zip
Archive Folder With Zip
... ${PDF_TEMP_OUTPUT_DIRECTORY}
... ${zip_file_name}
Cleanup temporary PDF directory
Remove Directory ${PDF_TEMP_OUTPUT_DIRECTORY} True
Excel file
The event participation information is stored in an Excel file (devdata/Data.xlsx
):
first_name | last_name | address | city | date | time |
---|---|---|---|---|---|
Reynard | Mouse | 4 Service Center | Toronto | 2019/07/03 | 10:00 PM |
Elisabeth | Kilfoyle | 197 Ronald Regan Drive | New York | 2019/05/03 | 10:20 PM |
Cyril | Blundon | 3554 Chive Circle | San Francisco | 2019/05/10 | 1:33 PM |
Vincenz | Paolazzi | 20533 6th Crossing | Milan | 2019/12/14 | 6:58 AM |
Jeannie | Charge | 9 Michigan Street | Kansas City | 2020/02/12 | 4:27 AM |
Alexio | Hellis | 8 Grim Trail | Lahore | 2019/05/05 | 5:04 PM |
Luca | Viel | 91764 Reindahl Park | New Dehli | 2019/12/17 | 8:37 AM |
Sly | Lammerts | 8077 Pennsylvania Drive | Helsinki | 2020/02/09 | 11:23 PM |
Leah | Mithun | 3619 Oxford Place | Stockholm | 2019/10/30 | 1:15 PM |
Maridel | Sneezum | 4 Cambridge Center | London | 2020/03/26 | 11:24 AM |
PDF template file
The example includes a invite.template
file in the devdata
folder:
<h1>Event Invitation</h1>
<br />
<p>Dear <b>{{first_name}} {{last_name}}</b>,</p>
<p>You are invited to our event on <b>{{date}}</b> at <b>{{time}}</b>, at <b>{{address}}</b>, <b>{{city}}</b>.</p>
<p>Bring a friend, and don't be late!</p>
<p>Kind regards,</p>
<p>Robot Events Inc.</p>
Last edit: May 4, 2022