[Qgis-developer] Rendering a map in QgsComposition on Win 7 / 8

Przemysław Gierski pgierski at o2.pl
Wed Apr 23 10:57:13 PDT 2014


Hello,

I'm writing a plugin for QGIS 2.2.0 which should render a pdf file with 
a map and some text.

I don't know if it's relevant, but I want to render only raster layers.

I got it working under Linux (current Arch) and Windows XP, but it's not 
working on Windows 7 or 8.

The plugin is to be runned from QGIS, so it has access to self.iface 
variable.

I've used code samples from tutorial.

Here is the code I use:

mapRenderer = self.iface.mapCanvas().mapRenderer()
mapRenderer.setLayerSet(input_map_layers) #list of map layers id's
mapRenderer.setOutputUnits(QgsMapRenderer.Millimeters)
mapRenderer.setOutputSize(QSize(map_width_on_print_mm, 
map_height_on_print_mm), 300)
mapRenderer.setExtent(rect)

c = QgsComposition(mapRenderer)
c.setPlotStyle(QgsComposition.Print)
c.setPaperSize(210,297)

composerMap = QgsComposerMap(c, 
14.7026,113.85,map_width_on_print_mm,map_height_on_print_mm)
composerMap.setFrameEnabled(True)
composerMap.setFrameOutlineWidth(0.5)
c.addItem(composerMap)

printer = QPrinter()
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName(unicode(input_data_fields['output_pdf_filename']))
printer.setPaperSize(QSizeF(c.paperWidth(), c.paperHeight()), 
QPrinter.Millimeter)
printer.setFullPage(True)
printer.setColorMode(QPrinter.Color)
printer.setResolution(c.printResolution())

pdfPainter = QPainter(printer)
paperRectMM = printer.pageRect(QPrinter.Millimeter)
paperRectPixel = printer.pageRect(QPrinter.DevicePixel)
c.render(pdfPainter, paperRectPixel, paperRectMM)
pdfPainter.end()


Can anyone help me with making it work under Win 7 / 8? What am I missing?

--
With best regards, Przemyslaw Gierski.


More information about the Qgis-developer mailing list