I am trying to export a specific layout with python in QGIS3. But I am struggling with the QgsLayoutExport class. How do you use it? How can specify which layout should be exported? This is the code I tried but it's not working. The layout in the brackets is the layout I want to export.


2 Answers 2


This a basic example how export to pdf where you can espify the layout.

projectInstance = QgsProject.instance()
layoutmanager = projectInstance.layoutManager()
layout = layoutmanager.layoutByName("test") #Layout name
exporter = QgsLayoutExporter(layout)
exporter.exportToPdf("C://test.pdf", QgsLayoutExporter.PdfExportSettings() )

You will also need to include PdfExportSettings() when using the exportToPdf() method. You can call the default values using QgsLayoutExporter.PdfExportSettings().

So your code could look like:

QgsLayoutExporter(layout).exportToPdf( filepath, QgsLayoutExporter.PdfExportSettings() )

Your Answer

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

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