当前位置: 首页>>代码示例>>Python>>正文


Python QPrinter.setFullPage方法代码示例

本文整理汇总了Python中PyQt4.QtGui.QPrinter.setFullPage方法的典型用法代码示例。如果您正苦于以下问题:Python QPrinter.setFullPage方法的具体用法?Python QPrinter.setFullPage怎么用?Python QPrinter.setFullPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtGui.QPrinter的用法示例。


在下文中一共展示了QPrinter.setFullPage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: exportPDF

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setFullPage [as 别名]
    def exportPDF(self, view, file_name, width, height):
        pdf = QPrinter()
        pdf.setOutputFormat(QPrinter.PdfFormat)
        pdf.setPrintRange(QPrinter.AllPages)
        pdf.setOrientation(QPrinter.Portrait)
        pdf.setResolution(QPrinter.HighResolution)
        pdf.setPaperSize(QSizeF(width, height), QPrinter.Point)
        pdf.setFullPage(True)
        pdf.setOutputFileName(file_name)
        view.mainFrame().print_(pdf)

        QApplication.restoreOverrideCursor()
开发者ID:danielfmva,项目名称:ert,代码行数:14,代码来源:export_plot.py

示例2: plotPDF

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setFullPage [as 别名]
    def plotPDF(self, width, height, output_file, units = "pixels", _plotting_object = None):

        """Plots the data specified in the current input file as a page in a
        PDF file with the given width and height, writing the output to the
        specified output file. The optional units argument specifies the units
        used to measure the plot size; by default, pixels are used, but "cm",
        "mm" and "in" are also acceptable.
        
        Returns the QPrinter object used to write the file."""

        pdf = QPrinter()
        pdf.setOutputFormat(QPrinter.PdfFormat)
        pdf.setOutputFileName(output_file)
        
        if units == "in":
            width = pdf.logicalDpiX() * width
            height = pdf.logicalDpiY() * height
        elif units == "cm":
            width = pdf.logicalDpiX() * (width / 2.54)
            height = pdf.logicalDpiY() * (height / 2.54)
        elif units == "mm":
            width = pdf.logicalDpiX() * (width / 25.4)
            height = pdf.logicalDpiY() * (height / 25.4)
        elif units != "pixels":
            raise BDianaError, "Unknown units specified to plotPDF: %s" % units

        pdf.setPaperSize(QSizeF(width, height), QPrinter.DevicePixel)
        pdf.setFullPage(True)
        return self._plot(width, height, pdf, _plotting_object)[0]
开发者ID:metno,项目名称:python-diana,代码行数:31,代码来源:bdiana.py

示例3: print_pdf

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setFullPage [as 别名]
	def print_pdf(self):
		if self.deck is not None:
			#Setting the printer
			printer = QPrinter(QPrinter.HighResolution)
			printer.setOutputFormat(QPrinter.PdfFormat)
			printer.setOrientation(getattr(QPrinter, "Portrait"))
			printer.setOutputFileName(self.path)
			printer.setPaperSize(getattr(QPrinter, self.paper))
			printer.setFullPage(True)
			guide = self.max_cards()
			printer.setOrientation(getattr(QPrinter, guide["orientation"]))
			print guide, self.card_size
			#Start printing
			with QPainter(printer) as paint:
				ind = 0
				resol = printer.resolution()
				for c in self.deck:
						c.resize(self.card_size[0], self.card_size[1])
						if ind == guide["max"]:
							printer.newPage()
							ind = 0

						col = ind % guide["horizontal"]
						fil = ind // guide["horizontal"]
						print ind, fil, col
						target = QRectF((col)*self.card_size[0]*resol, (fil)*self.card_size[1]*resol,
									self.card_size[0]*resol, self.card_size[1]*resol)

						self.preview_card(c)
						self.scene.render(paint, target=target, source=QRectF(0,0,c.width(),c.height()))
						ind += 1
开发者ID:Ja-vi,项目名称:pnp,代码行数:33,代码来源:printer.py

示例4: print_to_pdf

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setFullPage [as 别名]
    def print_to_pdf(self,
                     path,
                     paper_size    = (8.5, 11.0),
                     paper_margins = (0, 0, 0, 0),
                     paper_units   = QPrinter.Inch,
                     zoom_factor   = 1.0,
                     ):
        """Saves page as a pdf file.

        See qt4 QPrinter documentation for more detailed explanations
        of options.

        :param path: The destination path.
        :param paper_size: A 2-tuple indicating size of page to print to.
        :param paper_margins: A 4-tuple indicating size of each margin.
        :param paper_units: Units for pager_size, pager_margins.
        :param zoom_factor: Scale the output content.
        """
        assert len(paper_size) == 2
        assert len(paper_margins) == 4
        printer = QPrinter(mode = QPrinter.ScreenResolution)
        printer.setOutputFormat(QPrinter.PdfFormat)
        printer.setPaperSize(QtCore.QSizeF(*paper_size), paper_units)
        printer.setPageMargins(*(paper_margins + (paper_units,)))
        printer.setFullPage(True)
        printer.setOutputFileName(path)
        if self.webview is None:
          self.webview = QtWebKit.QWebView()
          self.webview.setPage(self.page)
        self.webview.setZoomFactor(zoom_factor)
        self.webview.print_(printer)
开发者ID:Awesoham,项目名称:Ghost.py,代码行数:33,代码来源:ghost.py

示例5: printWindow

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setFullPage [as 别名]
 def printWindow(self, printer=None):
     if not printer:
         printer = QPrinter()
     printer.setFullPage(True)
     printer.setPageSize(QPrinter.A4)
     dialog = QPrintDialog(printer, self)
     dialog.setWindowTitle(QCoreApplication.translate('QwtPlot', 'Print Document'))
     if dialog.exec_() != QDialog.Accepted:
         return
     self.plot.print_(printer, QwtPlotPrintFilter())
开发者ID:BackupTheBerlios,项目名称:simuvis4-svn,代码行数:12,代码来源:QwtPlotWindow.py

示例6: __saveAsPDF

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setFullPage [as 别名]
    def __saveAsPDF( self, fileName ):
        " Saves the flowchart as an PDF file "
        printer = QPrinter()
        printer.setOutputFormat( QPrinter.PdfFormat )
        printer.setPaperSize( QSizeF( self.scene.width(),
                                      self.scene.height() ), QPrinter.Point )
        printer.setFullPage( True )
        printer.setOutputFileName( fileName )

        painter = QPainter( printer )
        self.scene.render( painter )
        painter.end()
        return
开发者ID:fukanchik,项目名称:codimension,代码行数:15,代码来源:flowuiwidget.py

示例7: WebKitPDF

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setFullPage [as 别名]
class WebKitPDF ( QObject ):

  def __init__ ( self, url, dest ):
    QObject.__init__ ( self )
    self.dest = dest
    self.page = QtWebKit.QWebPage ( self )
    self.mainFrame = self.page.mainFrame()
    self.mainFrame.load ( QUrl ( url ) )

    # Settings
    # Disable the scrollbars
    self.mainFrame.setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
    self.mainFrame.setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)

    self.connect ( self.page,
             SIGNAL ( "loadProgress(int)" ),
             self.loadProgress )

    self.connect ( self.page,
             SIGNAL ( "loadFinished(bool)" ),
             self.renderPDF )



  def loadProgress ( self, progress ):
    print "Progress: ", progress


  def renderPDF ( self, status ):
    print "Load finished with status: ", status
    print "Rendering PDF ..."

    contentsSize = self.mainFrame.contentsSize()
    contentsSize.setWidth(1280)
    self.page.setViewportSize ( contentsSize )

    self.printer = QPrinter ( QPrinter.PrinterResolution )
    #self.printer = QPrinter ( QPrinter.ScreenResolution )
    self.printer.setOutputFormat ( QPrinter.PdfFormat )
    #self.printer.setPaperSize ( QPrinter.A4 )
    self.printer.setFullPage( True )
    self.printer.setPaperSize ( QSizeF( contentsSize ), QPrinter.DevicePixel )
    self.printer.setOrientation ( QPrinter.Portrait )
    self.printer.setOutputFileName ( self.dest )

    self.painter = QPainter ( self.printer )
    self.painter.setRenderHint ( QPainter.Antialiasing )
    self.mainFrame.render ( self.painter )
    self.painter.end()
    app = QtGui.QApplication.instance()
    app.exit ( 0 )
开发者ID:kholidfu,项目名称:htmlkepdf,代码行数:53,代码来源:gistfile2.py

示例8: printWindow

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setFullPage [as 别名]
 def printWindow(self, printer=None):
     if not printer:
         printer = QPrinter()
     printer.setFullPage(True)
     printer.setPageSize(QPrinter.A4)
     dialog = QPrintDialog(printer, self)
     dialog.setWindowTitle(QCoreApplication.translate('Graphics', 'Print Document'))
     if dialog.exec_() != QDialog.Accepted:
         return
     # FIXME: on windows the resolutions seems to be very low, why?
     #printer.setResolution(600)
     painter = QPainter(printer)
     painter.setRenderHint(QPainter.Antialiasing)
     self.graphicsView.scene().render(painter)
开发者ID:BackupTheBerlios,项目名称:simuvis4-svn,代码行数:16,代码来源:GraphicsWindow.py

示例9: _exportCompositionAsPDF

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setFullPage [as 别名]
 def _exportCompositionAsPDF(self,composition,filePath):  
     """
     Render the composition as a PDF file.
     """
     printer = QPrinter()
     printer.setOutputFormat(QPrinter.PdfFormat)
     printer.setOutputFileName(filePath)
     printer.setPaperSize(QSizeF(composition.paperWidth(),composition.paperHeight()),QPrinter.Millimeter)
     printer.setFullPage(True)
     printer.setColorMode(QPrinter.Color)
     printer.setResolution(composition.printResolution())
     
     #Use painter to send output to printer
     pdfPainter = QPainter(printer)
     paperRectMM = printer.pageRect(QPrinter.Millimeter)
     paperRectPixel = printer.pageRect(QPrinter.DevicePixel)
     composition.render(pdfPainter,paperRectPixel,paperRectMM)
     pdfPainter.end()
开发者ID:SolomonN,项目名称:stdm_plugin,代码行数:20,代码来源:document_generator.py

示例10: __createPdf

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setFullPage [as 别名]
	def __createPdf(self, savePath):
		"""
		Diese Funktion druckt den Charakter in ein PDF-Dokument.
		"""

		# Wenn Unterverzeichnis nicht existiert, erstelle es
		dirname = os.path.dirname(savePath)
		if not os.path.exists(dirname):
			os.makedirs(dirname)

		printer = QPrinter(QPrinter.PrinterResolution)
		#printer = QPrinter()

		printer.setOutputFormat( QPrinter.PdfFormat )
		printer.setPaperSize( QPrinter.A4 )
		printer.setFullPage( True )
		printer.setOutputFileName( savePath )

		drawSheet = RenderSheet( self.__storage, self.__character, printer, self )

		try:
			drawSheet.createSheets()
		except ErrSpeciesNotExisting as e:
			MessageBox.exception( self, e.message, e.description )
开发者ID:GoliathLeviathan,项目名称:SoulCreator,代码行数:26,代码来源:MainWindow.py

示例11: BatchPlottingDialog

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setFullPage [as 别名]

#.........这里部分代码省略.........
                        QApplication.restoreOverrideCursor()
                        return
                    if not self.ui.SingleFileCheckbox.checkState():
                        multiFilePrinter = QPrinter()
                        outputFileName = QDir( outputDir ).filePath( atlas.currentFilename() ) + ".pdf"
                        self.composition.beginPrintAsPDF( multiFilePrinter, outputFileName )
                        # set the correct resolution
                        self.composition.beginPrint( multiFilePrinter )
                        printReady = painter.begin( multiFilePrinter )
                        if not printReady:
                            QMessageBox.warning( self, tr( "Atlas processing error" ),
                                tr( "Error creating %s." % outputFileName ) )
                            progress.cancel()
                            QApplication.restoreOverrideCursor()
                            return
                        self.composition.doPrint( multiFilePrinter, painter )
                        painter.end()
                    else:
                        # start print on a new page if we're not on the first feature
                        if featureI > 0:
                            printer.newPage()
                        self.composition.doPrint( printer, painter )
                    
                atlas.endRender()
                if self.ui.SingleFileCheckbox.checkState():
                    painter.end()
                QApplication.restoreOverrideCursor()

            elif self.ui.OutputTab.currentIndex() == 1:  # to Printer
                # if To Printer is selected set the printer
                # setting up printer
                if self.printer is None:
                    self.printer = QPrinter()
                    self.printer.setFullPage(True)
                    self.printer.setColorMode(QPrinter.Color)
                # open printer setting dialog
                pdlg = QPrintDialog(self.printer,self)
                pdlg.setModal(True)
                pdlg.setOptions(QAbstractPrintDialog.None)
                if not pdlg.exec_() == QDialog.Accepted:
                    return
                
                QApplication.setOverrideCursor(Qt.BusyCursor)
                #prepare for first feature, so that we know paper size to begin with
                self.composition.setAtlasMode( QgsComposition.ExportAtlas )
                atlas.prepareForFeature(0)

                # set orientation                
                if self.composition.paperWidth() > self.composition.paperHeight():
                    self.printer.setOrientation(QPrinter.Landscape)
                    self.printer.setPaperSize(
                        QSizeF(self.composition.paperHeight(), self.composition.paperWidth()),
                        QPrinter.Millimeter)
                else:
                    self.printer.setOrientation(QPrinter.Portrait)
                    self.printer.setPaperSize(
                        QSizeF(self.composition.paperWidth(), self.composition.paperHeight()),
                        QPrinter.Millimeter)
                self.printer.setResolution(self.composition.printResolution())

                self.composition.beginPrint( self.printer )
                painter = QPainter(self.printer)
                if not len(atlas.featureFilterErrorString()) == 0:
                    QMessageBox.warning( self, tr( "Atlas processing error" ),
                        tr( "Feature filter parser error: %s" % atlas.featureFilterErrorString() ) )
                    QApplication.restoreOverrideCursor()
开发者ID:GEO-IASS,项目名称:ls,代码行数:70,代码来源:batch_plotting_dialog.py

示例12: save

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setFullPage [as 别名]
    def save(self, imgName, w=None, h=None, header=None, \
                 dpi=150, take_region=False):
        ext = imgName.split(".")[-1].upper()

        root = self.startNode
        #aspect_ratio = root.fullRegion.height() / root.fullRegion.width()
        aspect_ratio = self.i_height / self.i_width

        # auto adjust size
        if w is None and h is None and (ext == "PDF" or ext == "PS"):
            w = dpi * 6.4
            h = w * aspect_ratio
            if h>dpi * 11:
                h = dpi * 11
                w = h / aspect_ratio
        elif w is None and h is None:
            w = self.i_width
            h = self.i_height
        elif h is None :
            h = w * aspect_ratio
        elif w is None:
            w = h / aspect_ratio

        if ext == "SVG": 
            svg = QtSvg.QSvgGenerator()
            svg.setFileName(imgName)
            svg.setSize(QtCore.QSize(w, h))
            svg.setViewBox(QtCore.QRect(0, 0, w, h))
            #svg.setTitle("SVG Generator Example Drawing")
            #svg.setDescription("An SVG drawing created by the SVG Generator")
            
            pp = QtGui.QPainter()
            pp.begin(svg)
            targetRect =  QtCore.QRectF(0, 0, w, h)
            self.render(pp, targetRect, self.sceneRect())
            pp.end()

        elif ext == "PDF" or ext == "PS":
            format = QPrinter.PostScriptFormat if ext == "PS" else QPrinter.PdfFormat

            printer = QPrinter(QPrinter.HighResolution)
            printer.setResolution(dpi)
            printer.setOutputFormat(format)
            printer.setPageSize(QPrinter.A4)
            
            pageTopLeft = printer.pageRect().topLeft()
            paperTopLeft = printer.paperRect().topLeft()
            # For PS -> problems with margins
            # print paperTopLeft.x(), paperTopLeft.y()
            # print pageTopLeft.x(), pageTopLeft.y()
            # print  printer.paperRect().height(),  printer.pageRect().height()
            topleft =  pageTopLeft - paperTopLeft

            printer.setFullPage(True);
            printer.setOutputFileName(imgName);
            pp = QtGui.QPainter(printer)
            if header:
                pp.setFont(QtGui.QFont("Verdana",12))
                pp.drawText(topleft.x(),20, header)
                targetRect =  QtCore.QRectF(topleft.x(), 20 + (topleft.y()*2), w, h)
            else:
                targetRect =  QtCore.QRectF(topleft.x(), topleft.y()*2, w, h)

            if take_region:
                self.selector.setVisible(False)
                self.render(pp, targetRect, self.selector.rect())
                self.selector.setVisible(True)
            else:
                self.render(pp, targetRect, self.sceneRect())
            pp.end()
            return
        else:
            targetRect = QtCore.QRectF(0, 0, w, h)
            ii= QtGui.QImage(w, \
                                 h, \
                                 QtGui.QImage.Format_ARGB32)
            pp = QtGui.QPainter(ii)
            pp.setRenderHint(QtGui.QPainter.Antialiasing )
            pp.setRenderHint(QtGui.QPainter.TextAntialiasing)
            pp.setRenderHint(QtGui.QPainter.SmoothPixmapTransform)
            if take_region:
                self.selector.setVisible(False)
                self.render(pp, targetRect, self.selector.rect())
                self.selector.setVisible(True)
            else:
                self.render(pp, targetRect, self.sceneRect())
            pp.end()
            ii.save(imgName)
开发者ID:deep20192731,项目名称:Sentiment-Analysis,代码行数:90,代码来源:OLD_qt4render.py

示例13: export_all_features

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setFullPage [as 别名]

#.........这里部分代码省略.........
                new_ext.setYMinimum( bbox.yMinimum() - delta_height / 2)
                new_ext.setYMaximum(bbox.yMaximum() + delta_height / 2)
            else:
                new_width = old_ratio * new_ext.height()
                delta_width = new_width - new_ext.width()
                new_ext.setXMinimum(bbox.xMinimum() - delta_width / 2)
                new_ext.setXMaximum(bbox.xMaximum() + delta_width / 2)

            if VRP_DEBUG is True: QgsMessageLog.logMessage(u'bbox old:{0}'.format(compmap.extent().toString()), DLG_CAPTION)
            compmap.setNewExtent(new_ext)
            if VRP_DEBUG is True: QgsMessageLog.logMessage(u'bbox new:{0}'.format(compmap.extent().toString()), DLG_CAPTION)
            #round up to next 1000
            compmap.setNewScale(math.ceil((compmap.scale()/1000.0)) * 1000.0)
            if VRP_DEBUG is True: QgsMessageLog.logMessage(u'bbox new (after scale):{0}'.format(compmap.extent().toString()), DLG_CAPTION)

            #add ORTHO after new extent -> performance
            if not self.ortho is None:
                self.ortho_lyr = self.__add_raster_layer(self.ortho, self.lyrname_ortho)
                self.__reorder_layers()

            self.comp_leg = self.__get_items(QgsComposerLegend)
            self.comp_lbl = self.__get_items(QgsComposerLabel)


            self.__update_composer_items(self.settings.dkm_gemeinde(self.gem_name)['lyrnamegstk'])

            if VRP_DEBUG is True:
                QgsMessageLog.logMessage(u'paperWidth:{0} paperHeight:{1}'.format(composition.paperWidth(), composition.paperHeight()), DLG_CAPTION)

            printer = QPrinter()
            printer.setOutputFormat(QPrinter.PdfFormat)
            printer.setOutputFileName(self.pdf_map)
            printer.setPaperSize(QSizeF(composition.paperWidth(), composition.paperHeight()), QPrinter.Millimeter)
            printer.setFullPage(True)
            printer.setColorMode(QPrinter.Color)
            printer.setResolution(composition.printResolution())

            pdf_painter = QPainter(printer)
            paper_rect_pixel = printer.pageRect(QPrinter.DevicePixel)
            paper_rect_mm = printer.pageRect(QPrinter.Millimeter)
            QgsPaintEngineHack.fixEngineFlags(printer.paintEngine())
            #DKM only
            if len(self.themen) < 1:
                composition.render(pdf_painter, paper_rect_pixel, paper_rect_mm)
            else:
                self.statistics = OrderedDict()
                try:
                    pass
                    #lyr = QgsVectorLayer('/home/bergw/VoGIS-Raumplanung-Daten/Geodaten/Raumplanung/Flaechenwidmung/Dornbirn/Flaechenwidmungsplan/fwp_flaeche.shp', 'flaeiw', 'ogr')
                    #lyr.loadNamedStyle('/home/bergw/VoGIS-Raumplanung-Daten/Geodaten/Raumplanung/Flaechenwidmung/Vorarlberg/Flaechenwidmungsplan/fwp_flaeche.qml')
                    #QgsMapLayerRegistry.instance().addMapLayer(lyr)
                except:
                    QgsMessageLog.logMessage('new lyr:{0}'.format(sys.exc_info()[0]), DLG_CAPTION)
                #QgsMapLayerRegistry.instance().addMapLayer(lyr)
                cntr = 0
                for thema, sub_themen in self.themen.iteritems():
                    if VRP_DEBUG is True: QgsMessageLog.logMessage('drucke Thema:{0}'.format(thema.name), DLG_CAPTION)
                    if sub_themen is None:
                        layers = self.__add_layers(thema)
                        self.__calculate_statistics(thema, thema, layers)
                        #no qml -> not visible -> means no map
                        if self.__at_least_one_visible(layers) is True:
                            if cntr > 0:
                                printer.newPage()
                            self.__reorder_layers()
                            self.__update_composer_items(thema.name, layers=layers)
开发者ID:BergWerkGIS,项目名称:VoGIS-Raumplanung,代码行数:70,代码来源:vrpprintcomposer.py

示例14: _get_composer_pdf_image

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setFullPage [as 别名]
    def _get_composer_pdf_image(self, width, height, dpi):
        pdfpath = getTempfilePath('pdf')
        temp_size = os.path.getsize(pdfpath)

        p = QPrinter()
        p.setOutputFormat(QPrinter.PdfFormat)
        p.setOutputFileName(pdfpath)
        p.setPaperSize(QSizeF(self._c.paperWidth(), self._c.paperHeight()),
                       QPrinter.Millimeter)
        p.setFullPage(True)
        p.setColorMode(QPrinter.Color)
        p.setResolution(self._c.printResolution())

        pdf_p = QPainter(p)
        # page_mm = p.pageRect(QPrinter.Millimeter)
        # page_px = p.pageRect(QPrinter.DevicePixel)
        # self._c.render(pdf_p, page_px, page_mm)
        self._c.renderPage(pdf_p, 0)
        pdf_p.end()

        if temp_size == os.path.getsize(pdfpath):
            return False, ''

        filepath = getTempfilePath('png')
        # Poppler (pdftocairo or pdftoppm):
        # PDFUTIL -png -singlefile -r 72 -x 0 -y 0 -W 420 -H 280 in.pdf pngbase
        # muPDF (mudraw):
        # PDFUTIL -c rgb[a] -r 72 -w 420 -h 280 -o out.png in.pdf
        if PDFUTIL.strip().endswith('pdftocairo'):
            filebase = os.path.join(
                os.path.dirname(filepath),
                os.path.splitext(os.path.basename(filepath))[0]
            )
            call = [
                PDFUTIL, '-png', '-singlefile', '-r', str(dpi),
                '-x', '0', '-y', '0', '-W', str(width), '-H', str(height),
                pdfpath, filebase
            ]
        elif PDFUTIL.strip().endswith('mudraw'):
            call = [
                PDFUTIL, '-c', 'rgba',
                '-r', str(dpi), '-w', str(width), '-h', str(height),
                # '-b', '8',
                '-o', filepath, pdfpath
            ]
        else:
            return False, ''

        qDebug("_get_composer_pdf_image call: {0}".format(' '.join(call)))
        res = False
        try:
            subprocess.check_call(call)
            res = True
        except subprocess.CalledProcessError as e:
            qDebug("_get_composer_pdf_image failed!\n"
                   "cmd: {0}\n"
                   "returncode: {1}\n"
                   "message: {2}".format(e.cmd, e.returncode, e.message))

        if not res:
            os.unlink(filepath)
            filepath = ''

        return res, filepath
开发者ID:dudds6699,项目名称:QGIS,代码行数:66,代码来源:test_qgspallabeling_composer.py

示例15: QPrinter

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setFullPage [as 别名]
c.setPlotStyle(QgsComposition.Print)
compmap.setPreviewMode(QgsComposerMap.Render)
#compmap.updateItem()
#emit compmap.itemChanged();
#compmap.extentChanged();
#compmap.toggleAtlasPreview()
#compmap.setNewScale(compmap.scale()+1)
#c.setPrintResolution(150)
#print c.printResolution()
c.setPrintAsRaster(False)

printer = QPrinter()
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName(pdf_out)
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)

QgsPaintEngineHack.fixEngineFlags(printer.paintEngine())

#c.renderPage(pdfPainter, 0)
c.doPrint(printer,pdfPainter)

pdfPainter.end()
subprocess.call(('xdg-open', pdf_out))
开发者ID:BergWerkGIS,项目名称:VoGIS-Raumplanung,代码行数:32,代码来源:QgsCompositionTest2.py


注:本文中的PyQt4.QtGui.QPrinter.setFullPage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。