6

While saving an atlas as PDF in QGIS, I can manually change the settings shown the image using "PDF Export Settings" window.

enter image description here

How can I set those options using PyQGIS?

Minimal code:

layout_manager = QgsProject.instance().layoutManager()
layout = layout_manager.layoutByName('LAYOUT_NAME')

layout_exporter = QgsLayoutExporter(layout)    
layout_exporter.exportToPdf(path, QgsLayoutExporter.PdfExportSettings())

1 Answer 1

7

Setting those options using PyQGIS requires using QgsLayoutExporter.PdfExportSettings() instance.

pdf_settings = QgsLayoutExporter.PdfExportSettings()

Then;

  1. For "Always export as vector"
    pdf_settings.forceVectorOutput = True or False.

  2. For "Export RDF metadata"
    pdf_settings.exportMetadata = True or False.

  3. "Text export" options:

    • For "Always Export Text as Paths"
      pdf_settings.textRenderFormat = QgsRenderContext.TextFormatAlwaysOutlines

    • For "Always Export Text as Text Objects"
      pdf_settings.textRenderFormat = QgsRenderContext.TextFormatAlwaysText

  4. For "Disable tiled raster layer exports"
    pdf_settings.rasterizeWholeImage = True or False.

enter image description here

layout_manager = QgsProject.instance().layoutManager()
layout = layout_manager.layoutByName('LAYOUT_NAME')

pdf_settings = QgsLayoutExporter.PdfExportSettings()

pdf_settings.forceVectorOutput = True` # default False
pdf_settings.exportMetadata = False # default True
pdf_settings.rasterizeWholeImage = True # default False
pdf_settings.textRenderFormat = QgsRenderContext.TextFormatAlwaysText
# OR pdf_settings.textRenderFormat = QgsRenderContext.TextFormatAlwaysOutlines # default

layout_exporter = QgsLayoutExporter(layout)    
layout_exporter.exportToPdf(path, pdf_settings)

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.