- unzip this repo
- Edit standalone_generate_pdf.bat to set the
OSGEO4W_ROOT
to your install of QGIS. Edit path to your install ofpython.exe
too (line 21). - Open cmd window in the unzipped folder and run
standalone_generate_pdf.bat
. If everything goes ok you should see feedback in the console and a fileexport.pdf
will be created in the folder. If you didn't get the 'Hello from QGIS' message then there is a problem with the bat file config. See export_expected_result.pdf for an example output.
Edit this for your situation: standalone_generate_pdf.py
project_path = 'single_pdf.qgs'
template_path = 'single_pdf_a4_landscape.qpt'
composition.exportAsPDF('export.pdf')
change the filter_expression:
filter_expression = '"name" IN ("Burpham Ward", "Send Ward", "Merrow Ward", "Holy Trinity Ward")'
change the layer name 'data'
which the filter is applied to:
for layer in QgsMapLayerRegistry.instance().mapLayers().values():
if layer.name() == 'data':
lyr = layer
break
lyr.setSubsetString(filter_expression)
Specify coords to set the map canvas to:
make_pdf(500000, 150000, 505000, 155000, filter_expression)
Change the title:
substitution_map = {
'title': 'the title of my map'}
The script will print the pdf using the qpt template based on whatever layers are loaded in the 'single_pdf.qgs'
file.
Most of the script is from Tim Sutton's example here: