Webinar

November 3rd, 2021 12:00 PM EDT
Automation for Field Services & DistributionNovember 3rd, 2021 12:00 PM EDT
Learn how creating a digital workforce can improve your supply chain processes!

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.

Excel worksheet to PDF files

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

*** Keywords ***
Set up directories
    Create Directory    ${PDF_TEMP_OUTPUT_DIRECTORY}
    Create Directory    ${OUTPUT_DIR}

*** Keywords ***
Collect invitations from the Excel file
    Open Workbook    ${EXCEL_FILE_PATH}
    ${invitations}=    Read Worksheet    header=True
    Close Workbook
    [Return]    ${invitations}

*** Keywords ***
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}

*** Keywords ***
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}

*** Keywords ***
Cleanup temporary PDF directory
    Remove Directory    ${PDF_TEMP_OUTPUT_DIRECTORY}    True

*** 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

Excel file

The event participation information is stored in an Excel file (devdata/Data.xlsx):

first_namelast_nameaddresscitydatetime
ReynardMouse4 Service CenterToronto2019/07/0310:00 PM
ElisabethKilfoyle197 Ronald Regan DriveNew York2019/05/0310:20 PM
CyrilBlundon3554 Chive CircleSan Francisco2019/05/101:33 PM
VincenzPaolazzi20533 6th CrossingMilan2019/12/146:58 AM
JeannieCharge9 Michigan StreetKansas City2020/02/124:27 AM
AlexioHellis8 Grim TrailLahore2019/05/055:04 PM
LucaViel91764 Reindahl ParkNew Dehli2019/12/178:37 AM
SlyLammerts8077 Pennsylvania DriveHelsinki2020/02/0911:23 PM
LeahMithun3619 Oxford PlaceStockholm2019/10/301:15 PM
MaridelSneezum4 Cambridge CenterLondon2020/03/2611: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>

Learn more about the libraries mentioned on this page:

October 21, 2021