1

I am using PyQGIS with GGIS 3.

I'd like to export my map in a A3 size .pdf (so that my printer prints it directely in A3).

How do I do that?

I did not find the right settings for exporting the pdf.

layout = QgsProject.instance().layoutManager().layoutByName('Example')
pc = layout.pageCollection()
pc.page(0).setPageSize('A3', QgsLayoutItemPage.Orientation.Landscape)

exporter = QgsLayoutExporter(layout)

pdf_settings = QgsLayoutExporter.PdfExportSettings()
pdf_settings.dpi = 300
#pdf_settings.papersize = 'A3'  --> is there something alike?

exporter.exportToPdf(result_folder +"\\myA3.pdf", pdf_settings)

enter image description here

1

You could use the following to change the first page of your layout to A3 landscape:

layout = QgsProject.instance().layoutManager().layoutByName('Example')
pc = layout.pageCollection()
pc.page(0).setPageSize('A3', QgsLayoutItemPage.Orientation.Landscape)
  • I tried your suggestion and my .pdf is now A3. However, my template now does not fit anymore (see edits). Is there a trick to make everything A3 in one go? – SaskiaG Aug 22 at 11:46
  • Of course! You have to change the size of your objects "map", "legend" .. ! it's not magic – Fran Raga Aug 22 at 11:58
  • 1
    As @FranRaga mentioned, I don't think there is a setting which automatically stretches the items in the layout to fill out the space. You need to specify the position and size using something like: map = layout.itemById('map'); map.attemptMove(QgsLayoutPoint(10, 20, QgsUnitTypes.LayoutMillimeters)); map.attemptResize(QgsLayoutSize(200, 100, QgsUnitTypes.LayoutMillimeters)) – Joseph Aug 22 at 12:01
  • ok that's sad ;-) Thanks for your answers! – SaskiaG Aug 22 at 13:01
1

you need change this property in the page layout, not in pdf setting.

I add a proof of concept:

page = QgsLayoutItemPage(layout)
page.setPageSize('A3')
  • I added these two lines under my: layout = QgsProject.instance().layoutManager().layoutByName('Example') and it did not work :-S – SaskiaG Aug 22 at 11:43
  • The complete example is that of @Joseph – Fran Raga Aug 22 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.