Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export layout output via terminal #26131

Closed
qgib opened this issue Feb 27, 2018 · 4 comments
Closed

export layout output via terminal #26131

qgib opened this issue Feb 27, 2018 · 4 comments
Labels
Feature Request Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks

Comments

@qgib
Copy link
Contributor

qgib commented Feb 27, 2018

Author Name: Basil Eric Rabi (@basilrabi)
Original Redmine Issue: 18240

Redmine category:map_composer/printing


A terminal command like below, to print layouts by batches without opening the gui, would be nice.

qqis-layout -p project.qgs -l layoutName -o mymap.pdf

see https://gis.stackexchange.com/questions/167650/export-a-qgis-print-composer-file-qpt-as-pdf-from-the-command-line/167657#167657

@qgib qgib added Feature Request Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks labels May 25, 2019
@basilrabi
Copy link
Contributor

basilrabi commented Jul 29, 2019

I learned the workaround for this. You can make a python script like this:

#!/usr/bin/python3

import argparse
import os

from qgis.core import QgsApplication, QgsLayoutExporter, QgsProject

os.environ['QT_QPA_PLATFORM'] = 'offscreen'

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('project', help='project file path')
    parser.add_argument('layout', help='name of layout to be printed')
    parser.add_argument('output', help='name of the pdf output file')
    args = parser.parse_args()

    project_file = os.getcwd() + '/'  + args.project

    gui_flag = False
    app = QgsApplication([], gui_flag)
    app.initQgis()

    project = QgsProject.instance()
    project.setFileName(project_file)
    project.read()

    manager = QgsProject.instance().layoutManager()
    layout = manager.layoutByName(args.layout)

    exporter = QgsLayoutExporter(layout)
    exporter.exportToPdf(args.output,
                         QgsLayoutExporter.PdfExportSettings())

    app.exitQgis()

Then you can now print your layout by running the script via terminal.

@basilrabi
Copy link
Contributor

Hi @gioman , can we close this feature request?

@gioman
Copy link
Contributor

gioman commented Apr 19, 2020

Hi @gioman , can we close this feature request?

@basilrabi yes, but it would be better give an explanation why.

@gioman gioman closed this as completed Apr 19, 2020
@basilrabi
Copy link
Contributor

yes, but it would be better give an explanation why.

Creating a python script similar to this will be enough since the functionality needed is already exposed in the the python bindings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks
Projects
None yet
Development

No branches or pull requests

3 participants