4

I'm working on an automated PDF export from a QGIS layout. The export is scripted and works as expected on my development machine.

However, in order to integrate with a CI pipeline I need the process to be containerized and run on a server with no display. I've used both xvfb and xorg/xdummy to create a virtual display within the container to satisfy QGIS's need for a display (the process exits with an error code with no display), and I've also shared the local display with the container to eliminate any issues specific to a virtual display. In all cases it almost works, but SVG graphics do not behave quite right in the generated PDF. Some colours show up black and the scale bar appears to be the wrong size and backwards.

Code to generate the PDF

QgsApplication.setPrefixPath("/usr/bin/qgis", True)
qgs = QgsApplication([], False)
qgs.initQgis()
project = QgsProject.instance()
project.read("./main.qgs")

layoutmanager = project.layoutManager()
layout_item = layoutmanager.layoutByName(layout_name)
export = QgsLayoutExporter(layout_item)
export.exportToPdf(filename, QgsLayoutExporter.PdfExportSettings())

qgs.exitQgis()

Result from development machine (not containerized)

enter image description here

Result from container

enter image description here

The solid black bar to the left of the 0 is actually the scale bar - if I hide the scale bar in the layout it goes away - so it appears that the scale bar is both the wrong scale and extending in the wrong direction.

Can anyone tell me how to address the display issues in my containerized PDF export?

To reproduce:

  1. git clone https://github.com/Bulkley-Valley-Cross-Country-Ski-Club/mapping
  2. cd mapping
  3. git checkout BVN04
  4. docker build -t exporter ci
  5. docker run --rm -v $PWD:/export -e PDF_OUTPUT_PATH=/export/map.pdf exporter
  6. open map.pdf

1 Answer 1

3

I managed to fix this by simply upgrading from a debian:buster-slim Docker image to debian:bullseye-slim. Presumably there was some dependency (likely related to SVG) that was not being properly met in Buster, but is now met in Bullseye.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.