Created
April 15, 2019 15:22
-
-
Save kikislater/185fe92fb3add1add962cd68077ed0d9 to your computer and use it in GitHub Desktop.
Export QGIS 3 layout from pyqgis 3 script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
from qgis.core import (QgsProject, QgsLayoutExporter, QgsApplication) | |
QgsApplication.setPrefixPath("/usr", True) | |
gui_flag = False | |
app = QgsApplication([], gui_flag) | |
app.initQgis() | |
project_path = os.getcwd() + '/project.qgz' | |
project_instance = QgsProject.instance() | |
project_instance.setFileName(project_path) | |
project_instance.read() | |
manager = QgsProject.instance().layoutManager() | |
layout = manager.layoutByName("my_layout") # name of the layout | |
# or layout = manager.layouts()[0] # first layout | |
exporter = QgsLayoutExporter(layout) | |
exporter.exportToPdf(project_instance.absolutePath() + "/layout.pdf", | |
QgsLayoutExporter.PdfExportSettings()) | |
app.exitQgis() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment