Getting started with ReportLab development
Have you wanted to try using our software but feel intimidated? Here is an easy and quick way to get started.
The following will be a quick reduced summary of of our Hello World example.
Make sure you’ve got python installed. ReportLab (4.2.2) currently works up to python version 3.12. You should be able to call this from a terminal/cmd prompt
Make an account on our website to use the full version. This will be needed later.
Make a folder you want to work in then go to this folder in a terminal/cmd prompt using the commands below.
mkdir getting_started cd getting_started
We can now create a virtual environment.
python3.12 -m venv .
Then activate the virtual environment with one of the following (depending on the operating system you’re using).
. bin/activate - Unix/macOS Scripts\activate - Windows
Once done, your terminal/cmd prompt should have the name of the folder on the left of the current line like “(getting started) $”. This means it’s active.
Once the virtual environment is active, install rlextra. You will need to enter your username and password from step 2 when prompted.
pip install rlextra -i https://www.reportlab.com/pypi/
Make a file called getting_started.rml and copy & paste in the following
<!DOCTYPE document SYSTEM "rml.dtd"> <document filename="getting_started.pdf"> <template> <pageTemplate id="main"> <frame id="first" x1="72" y1="72" width="451" height="698"/> </pageTemplate> </template> <!-- This is your stylesheet --> <stylesheet> </stylesheet> <!-- The story (your content) starts below this comment --> <story> <para> Hello Again </para> </story> </document>
Finally we can run it. You can do so from the terminal/cmd prompt (once again depending on the OS):
rml2pdf getting_started.rml - Unix/macOS Scripts\rml2pdf.exe getting_started.rml.txt - Windows
OR, from inside a python file in the same directory you can the following:
# import rml2pdf from rlextra from rlextra.rml2pdf import rml2pdf # open rml with open("getting_started.rml", "r") as rml: # OR getting_started.rml.txt on windows rml2pdf.go(rml.read(), "getting_started.pdf") rml.close()
Once you’ve done this example feel free to check out some of our other resources:
Documentation: https://docs.reportlab.com/
Case studies: https://www.reportlab.com/casestudies/
Mixed Demos: https://docs.reportlab.com/demos/
Document Tutorial/Examples repo: https://docs.reportlab.com/rmlsamples/
Please check out the above Document Tutorial/Examples repo link which goes to our documentation website for more. Here is a mercurial command to pull down the examples code repository:
hg clone https://hg.reportlab.com/hg-public/rlextra-examples/