Hi all,

When using PyQGIS with Python 3.8 I can't seem to get the PostGIS layers of a 
QGIS layout to export to PDF while the local / shapefile layers will.

The manual export to PDF from the QGIS Layout window will export the PostGIS 
layers just fine along with the SHP layers.

From the code below, can anyone spot what I might be missing?

(Running QGIS 3.18 on Linux Mint 20 with Python 3.8)

Thank you, and let me know if more info is needed!

(BEGIN CODE)

#!/usr/bin/env python3
import os
from qgis.core import (
#layout and general
  QgsProject, QgsLayoutExporter, QgsApplication
 )

QgsApplication.setPrefixPath("/usr", True)
gui_flag = False
app = QgsApplication([], gui_flag)
app.initQgis()

project_path = os.getcwd() + '/rec_centers.qgz'
project_instance = QgsProject.instance()
project_instance.setFileName(project_path)
project_instance.read()

#print layer names in layout (not used anywhere else):
names = [layer.name() for layer in QgsProject.instance().mapLayers().values()]
print ('Layers in project: ', names)

#layout stuff
manager = QgsProject.instance().layoutManager()
layout = manager.layoutByName("test_layout") # name of the layout

#export stuff
exporter = QgsLayoutExporter(layout)
exporter.exportToPdf(project_instance.absolutePath() + "/output/layout.pdf",
                     QgsLayoutExporter.PdfExportSettings())

app.exitQgis()

(END CODE)

-m

--

MATTHEW BAKER
Spatial Information Manager
Denver Public Schools
Department of Enrollment and Campus Planning

1860 Lincoln St., Denver, CO 80203 | 11th Floor
720-423-3419 | matthew_ba...@dpsk12.org | planning.dpsk12.org

Students First . Integrity . Equity . Collaboration . Accountability . Fun .
_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to