How to pass images for report generation

Images help to make PDF printouts visually appealing. Based on your requirements to integrate static images (e.g. company logo) or dynamic images (e.g. product pictures) ReportBro supports various ways to pass them to the report.

In this tutorial you will learn how to pass an image:
base64 encoded
as file object
from URL
from local path

1 Base64 encoded image

You can provide a base64 encoded image as string. The string must contain the following format: 'data:image/<image type>;base64,<encoded image data>'

<image type> must either be "png", "jpg" or "jpeg". <encoded image data> contains the base64 encoded image data.

If you choose to upload a static image in ReportBro Designer the image will be saved as part of the report template in this format.

ReportBro Designer parameter type: Image

2 File object

The only way to provide an image file object is server side. Open a file and pass this file object to an image parameter, e.g.

logo_default = open('rbro_logo.png', 'rb')
report_data = dict(logo_default=logo_default)

ReportBro Designer parameter type: Image

3 Image from URL

You can point to an image specified by a URL. The URL must start with "http://" or "https://" and end with the image file extension. Allowed file extensions are "png", "jpg" or "jpeg". e.g. Also make sure the mapped parameter type in ReportBro Designer is string instead of image.

screenshot = ''
report_data = dict(screenshot=screenshot)

ReportBro Designer parameter type: String

4 Image from local path

You can point to a local image file specified by a URI. The URI must start with "file:". The path must be inside the current working directory (i.e. not contain any parent directory specifiers "..") and end with one of the supported file extensions "png", "jpg" or "jpeg". e.g. As for image from URL the mapped parameter type in ReportBro Designer has to be a string.

Local image file paths are not allowed if is_test_data flag of report instance is True (i.e. report is generated for preview in ReportBro Designer)

header_img = 'file:static/images/header.png'
report_data = dict(header_img)

ReportBro Designer parameter type: String

We have put together all variations of using images in ReportBro described in this tutorial so you can try it yourself: Download the report , Python script and the used Sample image and put all of them into the same directory.

Make sure you have the tornado lib installed

pip install tornado
and then execute the python script to start the web server. You can generate the report with this url in your browser: http://localhost:5000/report/image

By the way, ReportBro is also available for everyone as open-source on github (see Download page). Star us on github if you like what you see!