[Qgis-developer] Rendering a map in QgsComposition on Win 7 / 8
pgierski
pgierski at o2.pl
Thu May 8 03:23:03 PDT 2014
Hello,
I'm reposting this mail, because I didn't get any answer.
If any additional information is needed please ask me.
I'm writing a plugin for QGIS 2.2.0 which should render a pdf file with
a map and some text.
The code is working under Linux (current Arch) and Windows XP, but it's not
working on Windows 7 or 8. Output PDF on Win 7/8 has all labels, but no map, only blank space.
I don't know if it's relevant, but I want to render only raster layers.
The plugin is to be runned from QGIS, so it has access to self.iface
variable, but I can also use standalone QgsMapRenderer.
What am I missing?
Please help me! ;)
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()
--
With best regards, Przemyslaw Gierski.
More information about the Qgis-developer
mailing list