I've made a few maps in QGIS Composer and set them up initially as 8.5×11 page size. I want to begin with that layout and apply it to 11×17 page size. However when I change this in the Page Layout, only the page dimensions change. The symbol sizes should have changed as well but they look the same as if they were printed on an 8.5×11. The fonts also remain the same size in relation to the composer page. When the page is saved to PDF, Acrobat does not recognize that the page is 11×17 and still shows it as 8.5×11. Am I missing something?
[GIS] How to change page size in QGIS Composer
print-composerqgis
Related Solutions
You could also use "map units" instead of "points" to scale your labels and lines (you'll need rather huge values in most cases). This way your labels will always have a fixed size in relation to your map, and you'll be able to place them very precisely within the map canvas - no need to switch over to the composer (useful in very crowded maps).
This disadvantage is, of course, that you might not be able to read the labels in too small or large scales, because they might be either too small or too large.
I recommend using the following script by Tim Sutton as a base, it worked well for me:- http://kartoza.com/how-to-create-a-qgis-pdf-report-with-a-few-lines-of-python/
Just pass an empty dict to the composition.loadFromTemplate() function instead of the 'substitution map' he uses, since you're not interested in that functionality.
Also, since you asked about "export as image" rather than "export as PDF", you have to do a bit more work than use the exportAsPDF() member function.
Below is a modified version of Tim's code that should do the trick, working from an external Python script. Set the DPI, and project+composer file variables as required.
(If you are using the Python console within QGIS rather than doing this as an external script, you can get the current map canvas using the qgis.iface and don't need to do use all the project loading etc code).
import sys
from qgis.core import (
QgsProject, QgsComposition, QgsApplication, QgsProviderRegistry)
from qgis.gui import QgsMapCanvas, QgsLayerTreeMapCanvasBridge
from PyQt4.QtCore import QFileInfo
from PyQt4.QtXml import QDomDocument
gui_flag = True
app = QgsApplication(sys.argv, gui_flag)
# Make sure QGIS_PREFIX_PATH is set in your env if needed!
app.initQgis()
# Probably you want to tweak this
project_path = 'project.qgs'
# and this
template_path = 'template.qpt'
# Set output DPI
dpi = 300
canvas = QgsMapCanvas()
# Load our project
QgsProject.instance().read(QFileInfo(project_path))
bridge = QgsLayerTreeMapCanvasBridge(
QgsProject.instance().layerTreeRoot(), canvas)
bridge.setCanvasLayers()
template_file = file(template_path)
template_content = template_file.read()
template_file.close()
document = QDomDocument()
document.setContent(template_content)
ms = canvas.mapSettings())
composition = QgsComposition(ms)
composition.loadFromTemplate(document, {})
# You must set the id in the template
map_item = composition.getComposerItemById('map')
map_item.setMapCanvas(canvas)
map_item.zoomToExtent(canvas.extent())
# You must set the id in the template
legend_item = composition.getComposerItemById('legend')
legend_item.updateLegend()
composition.refreshItems()
dpmm = dpi / 25.4
width = int(dpmm * composition.paperWidth())
height = int(dpmm * composition.paperHeight())
# create output image and initialize it
image = QImage(QSize(width, height), QImage.Format_ARGB32)
image.setDotsPerMeterX(dpmm * 1000)
image.setDotsPerMeterY(dpmm * 1000)
image.fill(0)
# render the composition
imagePainter = QPainter(image)
composition.renderPage(imagePainter, 0)
imagePainter.end()
image.save("out.png", "png")
QgsProject.instance().clear()
QgsApplication.exitQgis()
Best Answer
For posterity (since I think I have discovered the issue here, or at least had a different one myself): there is a "Page Size" setting in the Layout>Page Setup dialog that does not modify the layout of the composition manager. I suspect that this is what you were talking about cndnflyr, since your description matches what I was doing (ineffectually) to a "T"... this merely modifies the printing properties of the composition.
What you want is the "Page Size" setting in the "Page Properties". In Q2.x, this setting was found at the top of the "Composition" tab; now in Q3.x, that tab has been renamed to "Layout" and the setting has been moved. You can still find the setting by right-clicking anywhere in the main frame of the Composition editor (like on your map) and click "Page Properties" from the resulting context menu here.