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


Python QPrinter.setPageSize方法代码示例

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


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

示例1: save_report

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageSize [as 别名]
    def save_report(self):
        """Save report"""
        filename = QFileDialog.getSaveFileName(
            self, "Save Report", self.save_dir,
            "HTML (*.html);;PDF (*.pdf);;Report (*.report)")
        if not filename:
            return QDialog.Rejected

        self.save_dir = os.path.dirname(filename)
        self.saveSettings()
        _, extension = os.path.splitext(filename)
        if extension == ".pdf":
            printer = QPrinter()
            printer.setPageSize(QPrinter.A4)
            printer.setOutputFormat(QPrinter.PdfFormat)
            printer.setOutputFileName(filename)
            self.report_view.print_(printer)
        elif extension == ".report":
            with open(filename, 'wb') as f:
                pickle.dump(self, f)
        else:
            frame = self.report_view.page().currentFrame()
            with open(filename, "w") as f:
                f.write(frame.documentElement().toInnerXml())
        self.report_changed = False
        return QDialog.Accepted
开发者ID:karoema,项目名称:orange3,代码行数:28,代码来源:owreport.py

示例2: on_actionPreview_activated

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageSize [as 别名]
 def on_actionPreview_activated( self ):
     printer = QPrinter()
     printer.setPageSize( QPrinter.Letter )
     web = "balancegeneral.php?date=%d+%d" % ( 
                                              self.dtPicker.date().month() ,
                                              self.dtPicker.date().year() )
     report = frmReportes( web , printer, self )
     report.exec_()
开发者ID:armonge,项目名称:EsquipulasPy,代码行数:10,代码来源:balancegeneral.py

示例3: writePdf

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageSize [as 别名]
def writePdf(dir_):
    newbody = originHTML.format(**htmlpara)

    printer = QPrinter()
    printer.setOutputFormat(QPrinter.PdfFormat)
    printer.setOutputFileName(dir_+'.pdf')
    printer.setPageSize(QPrinter.A4)
    text = QTextDocument()
    text.setHtml(newbody.decode('utf-8'))
    text.print_(printer)
开发者ID:lidingke,项目名称:fiberGeometry,代码行数:12,代码来源:pdf.py

示例4: printWindow

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageSize [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

示例5: init_print

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageSize [as 别名]
 def init_print(self, linenos=True, style="default"):
     app = QApplication(sys.argv)  # noqa
     doc = QTextDocument()
     doc.setHtml(
         self.highlight_file(linenos=linenos, style=style)
     )
     printer = QPrinter()
     printer.setOutputFileName(self.pdf_file)
     printer.setOutputFormat(QPrinter.PdfFormat)
     page_size_dict = {"a2": QPrinter.A2, "a3": QPrinter.A3, "a4": QPrinter.A4}
     printer.setPageSize(page_size_dict.get(self.size.lower(), QPrinter.A4))
     printer.setPageMargins(15, 15, 15, 15, QPrinter.Millimeter)
     doc.print_(printer)
     logging.info("PDF created at %s" % (self.pdf_file))
开发者ID:et0803,项目名称:code2pdf,代码行数:16,代码来源:code2pdf.py

示例6: printWindow

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageSize [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

示例7: writePdfabs

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageSize [as 别名]
def writePdfabs(dir_):
    updates = PDF_PARAMETER
    htmlpara.update(updates)
    newbody = originHTML.format(**htmlpara)
    # with open('t.html', 'wb') as f:
    #     f.write(newbody)
    #     f.close()
    printer = QPrinter()
    printer.setOutputFormat(QPrinter.PdfFormat)
    printer.setOutputFileName(dir_)
    printer.setPageSize(QPrinter.A4)
    text = QTextDocument()
    text.setHtml(newbody.decode('utf-8'))
    text.print_(printer)
开发者ID:lidingke,项目名称:fiberGeometry,代码行数:16,代码来源:pdf.py

示例8: print_pdf

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageSize [as 别名]
def print_pdf(html, filename):
    """ Print HTML to PDF. """

    wv = QWebView()
    wv.setHtml(html)

    # doc = QTextDocument()
    # doc.setHtml(html)

    printer = QPrinter()
    printer.setOutputFileName(filename)
    printer.setOutputFormat(QPrinter.PdfFormat)
    printer.setPageSize(QPrinter.A4)
    printer.setPageMargins(15, 15, 15, 15, QPrinter.Millimeter)

    # doc.print_(printer)
    wv.print_(printer)

    print("PDF Generated: " + filename)
开发者ID:Joisar,项目名称:Python-Scripts,代码行数:21,代码来源:g4g.py

示例9: open_html_in_print_preview_from_gui_thread

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageSize [as 别名]
def open_html_in_print_preview_from_gui_thread(html,
    html_document=QTextDocument, page_size=None, page_orientation=None):

     printer = QPrinter()
     printer.setPageSize(page_size or QPrinter.A4)
     printer.setOrientation(page_orientation or QPrinter.Portrait)
     dialog = QPrintPreviewDialog(printer)

     @QtCore.pyqtSlot(QPrinter)
     def render(printer):
         doc = html_document()
         doc.setHtml(html)
         doc.print_(printer)

     dialog.paintRequested.connect(render)
     # show maximized seems to trigger a bug in qt which scrolls the page down
     #dialog.showMaximized()
     desktop = QCoreApplication.instance().desktop()
     # use the size of the desktop instead to set the dialog size
     dialog.resize(desktop.width() * 0.75, desktop.height() * 0.75)
     dialog.exec_()
开发者ID:kurtraschke,项目名称:camelot,代码行数:23,代码来源:printer.py

示例10: preview

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageSize [as 别名]
 def preview(self):
     """
     Muestra el dialogo de vista previa de impresión
     """
     try:
         printer = QPrinter()
         printer.setOrientation(self.orientation)
         printer.setPageSize(self.pageSize)
         web = self.web + self.printIdentifier
         report = reports.frmReportes(web, printer, self)
         report.exec_()
     except NotImplementedError as inst:
         QMessageBox.information(
             self, qApp.organizationName(), u"No se ha implementado la función de impresión para este modulo"
         )
         logging.error(unicode(inst))
     except UserWarning as inst:
         QMessageBox.critical(self, qApp.organizationName(), unicode(inst))
         logging.error(unicode(inst))
     except Exception as inst:
         QMessageBox.critical(self, qApp.organizationName(), "Hubo un error al intentar mostrar su reporte")
         logging.critical(unicode(inst))
开发者ID:armonge,项目名称:EsquipulasPy,代码行数:24,代码来源:base.py

示例11: print_file

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageSize [as 别名]
def print_file(fileName, printFunction):
    """This method print a file

    This method print a file, fileName is the default fileName,
    and printFunction is a funcion that takes a QPrinter
    object and print the file,
    the print method
    More info on:http://doc.qt.nokia.com/latest/printing.html"""
    #TODO: Make that the option it's taken from settings. maybe
    #this should be a class to manage all cases?

    printer = QPrinter(QPrinter.HighResolution)
    printer.setPageSize(QPrinter.A4)
    printer.setOutputFileName(fileName)
    printer.setDocName(fileName)
#PRINT PREVIEW OPTIONS
#TODO: the follow imp. dipatch an error on execution time we need to review
#if the error belongs to qt
#    preview = QPrintPreviewDialog(printer)
#    preview.paintRequested[QPrinter].connect(printFunction)
#    preview.exec_()
    dialog = QPrintDialog(printer)
    if dialog.exec_():
        printFunction(printer)
开发者ID:beefsack,项目名称:ninja-ide,代码行数:26,代码来源:ui_tools.py

示例12: QApplication

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageSize [as 别名]
from PyQt4.QtGui import QTextDocument, QPrinter, QApplication
import sys

app = QApplication(sys.argv)

doc = QTextDocument()
location = sys.argv[1]
html = open(location).read()
doc.setHtml(html)

printer = QPrinter()
printer.setOutputFileName(sys.argv[2])
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setPageSize(QPrinter.A4)
printer.setPageMargins(15,15,15,15,QPrinter.Millimeter);

doc.print_(printer)
print "\n" + sys.argv[2] + " was created successfully.\n"
开发者ID:connorkendrick,项目名称:html-pdf-gen,代码行数:20,代码来源:pdfgen.py

示例13: Form

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageSize [as 别名]
class Form(QDialog):
    def __init__(self, args=None,parent=None):
        super(Form, self).__init__(parent)
        self.printer = QPrinter()
        self.printer.setPageSize(QPrinter.A4)
        self.filename = ''
        #File name to convert
        lblFileName = QLabel("File Name")
        self.txtFileName = QLineEdit()
        if len(args) > 1:
          self.txtFileName.setText(args[1])
          self.filename = args[1]
        self.txtFileName.setReadOnly(True)
        btnGetFileName = QToolButton()
        btnGetFileName.setText("..")
        getFileLayout = QHBoxLayout()
        getFileLayout.addWidget(lblFileName)
        getFileLayout.addWidget(self.txtFileName)
        getFileLayout.addWidget(btnGetFileName)
        
        #Code page of file
        lblCodePage = QLabel("Code Page")
        self.cmbCodePage = QComboBox()
        self.cmbCodePage.addItem("dos")
        self.cmbCodePage.addItem("windows")
        self.cmbCodePage.addItem("utf8")
        codePageLayout = QHBoxLayout()
        codePageLayout.addStretch()
        codePageLayout.addWidget(lblCodePage)
        codePageLayout.addWidget(self.cmbCodePage)
       
        
        #Printer Orientation (Portrait / Landscape)
        lblOrientation = QLabel("Orientation")
        self.cmbOrientation = QComboBox()
        self.cmbOrientation.addItem("portait")
        self.cmbOrientation.addItem("landscape")
        orientationLayout = QHBoxLayout()
        orientationLayout.addStretch()
        orientationLayout.addWidget(lblOrientation)
        orientationLayout.addWidget(self.cmbOrientation)
        
        
        #Buttons for save or Just quit
        bSave = QPushButton("Go for it")
        bQuit = QPushButton("Abort")
        buttonLayout = QHBoxLayout()
        buttonLayout.addWidget(bQuit)
        buttonLayout.addStretch()
        buttonLayout.addWidget(bSave)
        
        #Final Layout
        layout = QVBoxLayout()
        layout.addLayout(getFileLayout)
        layout.addLayout(codePageLayout)
        layout.addLayout(orientationLayout)
        layout.addLayout(buttonLayout)
        self.setLayout(layout)
        
        #Connections
        self.connect(bSave, SIGNAL("clicked()"),self.printViaQPainter)
        self.connect(bQuit, SIGNAL("clicked()"), self.accept)
        self.connect(btnGetFileName, SIGNAL("clicked()"),self.getFileName)
        self.setWindowTitle("dos/windows text to PDF")
        
    def getFileName(self):
        fd = QFileDialog(self)
        self.filename = fd.getOpenFileName()
        self.txtFileName.setText(self.filename)
        
    def printViaQPainter(self):
        from os.path import isfile
        if isfile(self.filename):
            lines = open(self.filename)
        else:
            return
        a = self.filename.split('.')
        s = a[-1]
        fname = ''
        for i in range(len(a)-1) :
          fname += a[i]
        fname += '.pdf'        
        self.printer.setOutputFileName(fname)
        self.printer.setOutputFormat(QPrinter.PdfFormat)
        if self.cmbOrientation.currentText() == 'landscape':
            self.printer.setOrientation(QPrinter.Landscape)
        pageRect = self.printer.pageRect()
        LeftMargin = 15
        biggest = findBiggestLine(self.filename)
        bestSize = findBestFontSize(biggest,pageRect)
        sansFont = QFont("Courier", bestSize)
        sansLineHeight = QFontMetrics(sansFont).height()
        painter = QPainter(self.printer)
        page = 1
        y = 20
        cpage = codePage(self.cmbCodePage.currentText())
        for line in lines:
            painter.save()
            painter.setFont(sansFont)
            y += sansLineHeight
#.........这里部分代码省略.........
开发者ID:tedlaz,项目名称:m13,代码行数:103,代码来源:dw2pdf.py

示例14: save

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageSize [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

示例15: Window

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

#.........这里部分代码省略.........
            if self.image.save(self.filename, None):
                self.updateStatus("Saved as {0}".format(self.filename))
                self.dirty = False
                return True
            else:
                self.updateStatus("Failed to save {0}".format(
                                  self.filename))
                return False


    def fileSaveAs(self):
        if self.image.isNull():
            return True
        fname = self.filename if self.filename is not None else "."
        formats = (["*.{0}".format(unicode(format).lower())
                for format in QImageWriter.supportedImageFormats()])
        fname = unicode(QFileDialog.getSaveFileName(self,
                "Image Changer - Save Image", fname,
                "Image files ({0})".format(" ".join(formats))))
        if fname:
            if "." not in fname:
                fname += ".png"
            self.addRecentFile(fname)
            self.filename = fname
            return self.fileSave()
        return False


    def filePrint(self):
        if self.image.isNull():
            return
        if self.printer is None:
            self.printer = QPrinter(QPrinter.HighResolution)
            self.printer.setPageSize(QPrinter.Letter)
        form = QPrintDialog(self.printer, self)
        if form.exec_():
            painter = QPainter(self.printer)
            rect = painter.viewport()
            size = self.image.size()
            size.scale(rect.size(), Qt.KeepAspectRatio)
            painter.setViewport(rect.x(), rect.y(), size.width(),
                                size.height())
            painter.drawImage(0, 0, self.image)


    def editInvert(self, on):
        if self.image.isNull():
            return
        self.image.invertPixels()
        self.showImage()
        self.dirty = True
        self.updateStatus("Inverted" if on else "Uninverted")


    def editSwapRedAndBlue(self, on):
        if self.image.isNull():
            return
        self.image = self.image.rgbSwapped()
        self.showImage()
        self.dirty = True
        self.updateStatus(("Swapped Red and Blue"
                           if on else "Unswapped Red and Blue"))


    def editUnMirror(self, on):
        if self.image.isNull():
开发者ID:imagingearth,项目名称:PyQt4-Examples,代码行数:70,代码来源:MainWindow_ans.py


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