<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p><font face="Helvetica, Arial, sans-serif">Hi all,</font></p>
<p><font face="Helvetica, Arial, sans-serif">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.
<br>
</font></p>
<p><font face="Helvetica, Arial, sans-serif">The manual export to PDF from the QGIS Layout window will export the PostGIS layers just fine along with the SHP layers.<br>
</font></p>
<p><font face="Helvetica, Arial, sans-serif">From the code below, can anyone spot what I might be missing?
<br>
</font></p>
<p><font face="Helvetica, Arial, sans-serif">(Running QGIS 3.18 on Linux Mint 20 with Python 3.8)<br>
</font></p>
<p><font face="Helvetica, Arial, sans-serif">Thank you, and let me know if more info is needed!</font></p>
<p><font face="Helvetica, Arial, sans-serif">(BEGIN CODE)<br>
</font></p>
<p><font face="Helvetica, Arial, sans-serif"><font face="Courier
          New, Courier, monospace">#!/usr/bin/env python3<br>
import os<br>
from qgis.core import (<br>
#layout and general<br>
  QgsProject, QgsLayoutExporter, QgsApplication<br>
 )<br>
<br>
QgsApplication.setPrefixPath("/usr", True)<br>
gui_flag = False<br>
app = QgsApplication([], gui_flag)<br>
app.initQgis()<br>
<br>
project_path = os.getcwd() + '/rec_centers.qgz'<br>
project_instance = QgsProject.instance()<br>
project_instance.setFileName(project_path)<br>
project_instance.read()<br>
<br>
#print layer names in layout (not used anywhere else):<br>
names = [layer.name() for layer in QgsProject.instance().mapLayers().values()]<br>
print ('Layers in project: ', names)<br>
<br>
#layout stuff<br>
manager = QgsProject.instance().layoutManager()<br>
layout = manager.layoutByName("test_layout") # name of the layout<br>
<br>
#export stuff<br>
exporter = QgsLayoutExporter(layout)<br>
exporter.exportToPdf(project_instance.absolutePath() + "/output/layout.pdf",<br>
                     QgsLayoutExporter.PdfExportSettings())<br>
<br>
app.exitQgis()</font><br>
</font></p>
<p><font face="Helvetica, Arial, sans-serif">(END CODE)<br>
</font></p>
<p><font face="Helvetica, Arial, sans-serif">-m<br>
</font></p>
<div class="moz-signature">-- <br>
<p style="line-height:15.75pt;"><span style="font-family:
          "Rockwell", serif; color: rgb(0, 118, 189);">MATTHEW BAKER<br>
</span><span style="font-size: 14px;"><span style="font-family:
            "Rockwell", serif; color: rgb(0, 118, 189);">Spatial Information Manager</span><br>
<span style="font-family: "Rockwell", serif; color:
            rgb(0, 118, 189);">Denver Public Schools</span><br>
</span><span style="font-size: 14px; font-family:
          "Rockwell", serif; color: rgb(0, 118, 189);">Department of Enrollment and Campus Planning</span></p>
<p style="line-height:15.0pt;"><span style="font-size: 12px;"><span style="font-family: "Tahoma", sans-serif; color:
            rgb(135, 134, 135);">1860 Lincoln St., Denver, CO 80203 </span><span style="font-family: "Tahoma", sans-serif; color:
            rgb(0, 118, 189);">| </span><span style="font-family:
            "Tahoma", sans-serif; color: rgb(135, 134, 135);">11<sup>th</sup>
 Floor</span></span><span style="font-size: 12px;"><br>
</span><span style="font-family: "Tahoma", sans-serif;
          color: rgb(135, 134, 135); font-size: 12px;">720-423-3419</span><span style="font-family: "Rockwell", serif; color: rgb(0,
          118, 189);"><span style="font-size: 12px;"> | matthew_baker@</span><span style="color: rgb(0, 118, 189); font-size: 12px;">dpsk12.org
 | planning.dpsk12.org</span></span></p>
<p style="line-height:15.75pt;"><span style="font-size:13px;font-family:"Tahoma",sans-serif;color:#8BBF3F;">Students First . </span><span style="font-size: 13px;"><span style="font-family: "Tahoma", sans-serif; color:
            rgb(2, 76, 123);">Integrity
 . </span><span style="font-family: "Tahoma", sans-serif; color:
            rgb(223, 88, 42);">Equity . </span><span style="font-family:
            "Tahoma", sans-serif; color: rgb(181, 31, 110);">Collaboration . </span><span style="font-family: "Tahoma",
            sans-serif; color: rgb(40, 165, 222);">Accountability
 . </span><span style="font-family: "Tahoma", sans-serif; color:
            rgb(173, 31, 42);">Fun .</span></span></p>
</div>
</body>
</html>