Create a PDF using Python script

Build a bot that runs Python script from a file and generates a PDF.

Prerequisites

  • To run Python script from Automation 360, you must already have the latest version of Python 3.x installed on your device.
  • This example uses the FPDF library to generate the PDF. Therefore, install it before you start building this bot by copying and pasting the following line in the Windows command prompt:
    pip install fpdf
    See FPDF project page.

Procedure

  1. Create a file in a standalone folder to hold the following Python script:
    Insert your device username in the angle brackets.
    from fpdf import FPDF
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Arial", size=12)
    pdf.cell(200, 10, txt="Go Be Great!", ln=1, align="C")
    pdf.output("C:/Users/<yourusername>/Desktop/sample_demo.pdf")
    Note: If you are uploading a script from a file on your desktop, the file and any dependencies must be in a standalone folder. When you select a file for upload, all files and folders at the same folder level are uploaded.
  2. Create a new bot:
    1. On the left panel, click Automation.
    2. Click Create new > Bot.
    3. In the Create Task Bot window, enter the bot name.
    4. Accept the default folder location: \Bots\
      To change the default bot storage location, click Choose and follow the prompts.
    5. Click Create and edit.
  3. Provide the script with a Python Script > Open action:
    1. Double-click or drag the Python Script > Open.
    2. Select the Import existing file option.
    3. Click Browse to select the .py file you created in Step 1.
  4. Use a Python Script > Execute script action to tell the bot to run the script:
    1. Double-click or drag Python Script > Execute script.
  5. Close the script execution session with a Python Script > Close action:
    1. Double-click or drag Python Script > Close.
    2. Click Save.
  6. Click the Run icon.
    The bot creates a PDF on the desktop with the text Go Be Great!.

    To review the bot launcher logs, navigate to C:\ProgramData\AutomationAnywhere\BotRunner\Logs\<current month>\Bot_Launcher-<today's date>.log.zip. Each zipped folder contains a file with data on the code execution, which is useful for debugging.

    If the bot does not create a file, change the last line in the Python script:
    pdf.output(r"C:/Users/<yourusername>/Desktop/sample_demo.pdf")