I would like to open the QGIS Print layout by using Python.
I found some hints here:
but unfortunately everywhere is the same problem. I am getting an error:
IndentationError: unexpected indent
and I don't really know how to solve it
My simple code looks like this:
project = QgsProject.instance() manager = project.layoutManager() layout = QgsPrintLayout(project) layoutName = "Strand_012" #initializes default settings for blank print layout canvas layout.initializeDefaults() layout.setname(layoutName) manager.addLayout(layout) canvas = iface.mapCanvas() map.setExtent(canvas.extent()) layout.addLayoutItem(map)
I would like to open my map canvas in print layout and export it as PNG setting 170 Dpi resolution for it. How can I do it?