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


Python QtPrintSupport.QPrinter类代码示例

本文整理汇总了Python中PyQt5.QtPrintSupport.QPrinter的典型用法代码示例。如果您正苦于以下问题:Python QPrinter类的具体用法?Python QPrinter怎么用?Python QPrinter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: print_file

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"""

    printer = QPrinter(QPrinter.HighResolution)
    printer.setPageSize(QPrinter.A4)
    printer.setOutputFileName(fileName)
    printer.setDocName(fileName)

    preview = QPrintPreviewDialog(printer)
    preview.paintRequested['QPrinter*'].connect(printFunction)
    size = QApplication.instance().desktop().screenGeometry()
    width = size.width() - 100
    height = size.height() - 100
    preview.setMinimumSize(width, height)
    preview.exec_()
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:21,代码来源:ui_tools.py

示例2: filePrintPdf

    def filePrintPdf(self):
        fn, _ = QFileDialog.getSaveFileName(self, "Export PDF", None, "PDF files (*.pdf);;All Files (*)")

        if fn:
            if QFileInfo(fn).suffix().isEmpty():
                fn += ".pdf"

            printer = QPrinter(QPrinter.HighResolution)
            printer.setOutputFormat(QPrinter.PdfFormat)
            printer.setOutputFileName(fn)
            self.textEdit.document().print_(printer)
开发者ID:death-finger,项目名称:Scripts,代码行数:11,代码来源:textedit.py

示例3: actionPrintSlot

 def actionPrintSlot(self) -> None:
     printer = QPrinter()
     printer.setPageOrientation(QPageLayout.Landscape)
     if QPrintDialog(printer).exec_():
         painter = QPainter(printer)
         painter.setRenderHint(QPainter.Antialiasing)
         view = QGraphicsView()
         view.setScene(self.scene)
         view.setSceneRect(QRectF(0, 0, 290, 200))
         view.fitInView(QRectF(0, 0, 290, 200), Qt.KeepAspectRatio)
         view.scale(1, -1)
         view.render(painter)
         del painter  # necessary, thanks Qt
开发者ID:Longhanks,项目名称:QGVisualizer,代码行数:13,代码来源:mainwindow.py

示例4: printPdf

 def printPdf(self, frame):
      element = self.getPostElement(frame.documentElement())
      if element is not None:
         rect = element.geometry()
         pdf = QPrinter(QPrinter.ScreenResolution)
         pdf.setFullPage(True)
         pdf.setPrintRange(QPrinter.AllPages)
         pdf.setOutputFileName(self.getName(element))
         pdf.setOutputFormat(QPrinter.PdfFormat)
         element.webFrame().print(pdf)
开发者ID:luckywqf,项目名称:wordpress_blog_to_pdf,代码行数:10,代码来源:blogtopdf.py

示例5: initTestPageWebView

    def initTestPageWebView(self):
        
        widget = QWidget()
        
        self.testPageWebView = TestPageWebView()
        refreshButton = QPushButton("Refresh")
        pdfButton = QPushButton("Save PDF")

        buttons = QWidget()
        h2 = QHBoxLayout()
        h2.addWidget(pdfButton)        
        h2.addWidget(refreshButton)     
        h2.setSizeConstraint(QLayout.SetFixedSize)
        buttons.setLayout(h2)        

        v1 = QVBoxLayout()
        v1.addWidget(self.testPageWebView)        
        v1.addWidget(buttons)     
        widget.setLayout(v1)
        
        self.testPageWebView.init()
        
        def setitem(testobj):
            # set testfolder item
            self.tester.setitem(testobj)
            
            # set
            if testobj:
                testhtml, testurl, testhtmlpath = self.tester.getinfopanelhtml(testobj)
                
                if testhtmlpath:
                    self._testhtmlpathpdf = testhtmlpath.with_suffix(".pdf")
                    self.printer.setOutputFileName(str(self._testhtmlpathpdf))
                    
                testqurl = QUrl("file://{}/".format(testurl.resolve()))
                self.testPageWebView.setHtml(testhtml, testqurl)
                    
                
            else:
                self.testPageWebView.setHtml("<html></html>", QUrl())
        
        # Connect Buttons
        self.testitemchanged.connect(lambda obj: setitem(obj) )
        refreshButton.clicked.connect(lambda obj: setitem(self.__current_item) )
        
        ## Save PDF Button
        self.printer = QPrinter()
        self.printer.setPageSize(QPrinter.A4)
        self.printer.setOutputFormat(QPrinter.PdfFormat)
 
        def savePdf():
            self.testPageWebView.print_(self.printer)
            
            msg = "PDF Saved: "+str(self._testhtmlpathpdf)
            print(msg)
            QMessageBox.information(self,"Information",msg)        
        
        pdfButton.clicked.connect(savePdf)
        
        return widget
开发者ID:manasdas17,项目名称:scilab-2,代码行数:60,代码来源:guiprocessor.py

示例6: PdfConverter

def PdfConverter(username):

        htmllink = "bootstrap_mod/usertemp/"+username+".html"
        app1 = QApplication(sys.argv)

        web = QWebView()

        link =QUrl.fromLocalFile(QFileInfo(htmllink).absoluteFilePath())

        web.load(QUrl(link))

        printer = QPrinter()
        printer.setPageSize(QPrinter.A4)
        printer.setOutputFormat(QPrinter.PdfFormat)
        Pdf_Generated_Name="bootstrap_mod/usertemp/"+username+".pdf"
        printer.setOutputFileName(Pdf_Generated_Name)

        web.print(printer)
        QApplication.exit()
        def convertIt():
                web.print(printer)
                print("Pdf generated")
                QApplication.exit()

        web.loadFinished.connect(convertIt)
        sys.exit(app1.exec_())
        return 0
开发者ID:moredain,项目名称:zp,代码行数:27,代码来源:webkit.py

示例7: on_click

    def on_click(self, event):
        #print(self.editor.toPlainText())
        #print(self.editor.toHtml())

        # https://doc.qt.io/qt-5/qtextdocumentwriter.html
        #writer = QtGui.QTextDocumentWriter('output.odf')
        writer = QtGui.QTextDocumentWriter()

        for item in writer.supportedDocumentFormats():
            print('format:', bytes(item).decode())

        doc = self.editor.document()

        writer.setFormat(b'ODF') # has to be bytes, not string
        writer.setFileName('output.odf')
        writer.write(doc)

        writer.setFormat(b'HTML') # has to be bytes, not string
        writer.setFileName('output.html')
        writer.write(doc)
        
        writer.setFormat(b'plaintext') # has to be bytes, not string
        writer.setFileName('output.txt')
        writer.write(doc)

        printer = QPrinter()
        printer.setOutputFormat(QPrinter.PdfFormat)
        printer.setPaperSize(QPrinter.A4);
        printer.setOutputFileName('output.pdf')
        #doc.setPageSize(printer.pageRect().size()) # need QSizeF instead of QSize
        doc.print(printer)
开发者ID:golubaca,项目名称:python-examples,代码行数:31,代码来源:main.py

示例8: exportToPDF

    def exportToPDF(self, path=None):
        if path is None:
            desktop = QStandardPaths.standardLocations(
                QStandardPaths.DesktopLocation)
            path = os.path.join(desktop[0], "metricsWindow.pdf")

        printer = QPrinter()
        # printer.setFullPage(True)
        printer.setOutputFileName(path)
        printer.setOutputFormat(QPrinter.PdfFormat)

        painter = QPainter()
        painter.begin(printer)
        painter.setRenderHint(QPainter.Antialiasing)
        if self._rightToLeft:
            self.paintRightToLeft(painter, self.geometry())
        else:
            self.paintLeftToRight(painter, self.geometry())
        painter.end()
开发者ID:yodamaster,项目名称:trufont,代码行数:19,代码来源:metricsWindow.py

示例9: standardPrinter

	def standardPrinter(self, title):
		printer = QPrinter(QPrinter.HighResolution)
		printer.setDocName(title)
		printer.setCreator('ReText %s' % app_version)
		if globalSettings.paperSize:
			pageSize = self.getPageSizeByName(globalSettings.paperSize)
			if pageSize is not None:
				printer.setPaperSize(pageSize)
			else:
				QMessageBox.warning(self, '',
					self.tr('Unrecognized paperSize setting "%s".') %
					globalSettings.paperSize)
		return printer
开发者ID:starofrainnight,项目名称:retext,代码行数:13,代码来源:window.py

示例10: __init__

    def __init__(self, fft_mainWindow,parent=None, screenDim=None):

        super(ReportDialog, self).__init__(parent)
        self.fft_mainWindow=fft_mainWindow
        self.dataList = []
        self.setupUi(self, screenDim)
        self.screenDim = screenDim
        self.document = QTextDocument()
        #list that keeps track of only selected images
        self.list = []
        #list that contains all of the stored images
        self.wholeList = OrderedSet()
        self.savedfiles = None
        self.currentModel = None
        # settings
        self.uCut = 0
        self.lCut = 0
        self.angleInc = 0
        self.radStep = 0
        #  states
        """
        0 -> single
        1 -> multiple
        2 -> append
        """
        self.isReport = True
        self.isSummary = False
        self.reportOption = 2
        self.merger = merger()
        # printer
        self.printer = QPrinter(QPrinter.PrinterResolution)
        # Signals and slots:
        self.do_excel.connect(self.exportExcel)
        self.webView = QtWebKitWidgets.QWebView()

        # self.checkBox_report.stateChanged.connect(self.topLogicHandler)
        self.checkBox_summary.stateChanged.connect(self.topLogicHandler)

        self.radio_multiple.toggled.connect(self.toggleHandler)
        self.radio_single.toggled.connect(self.toggleHandler)
        self.radio_append.toggled.connect(self.toggleHandler)

        self.buttonBox.button(QDialogButtonBox.Ok).clicked.connect(self.exportHandler)
        self.do_print.connect(self.print)
        self.rejected.connect(self.resetOptions)
        self.topLogicHandler()
开发者ID:NTMatBoiseState,项目名称:FiberFit,代码行数:46,代码来源:report.py

示例11: __init__

    def __init__(self, parent=None, html=None):
        super(PrintHtml, self).__init__(parent)

        # html = codecs.open(b"template.html", encoding='utf-8').read()
        baseurl = QUrl.fromLocalFile(os.getcwd() + "/temp/index.html")
        self.setHtml(html, baseurl)
        self.printer = QPrinter()
        self.printer.setPageSize(QPrinter.A4)
        self.printer.setOrientation(QPrinter.Portrait)
        self.printer.setPageMargins(5, 5, 5, 5, QPrinter.Millimeter)
        self.setFixedWidth(1000)

        dialog = QPrintPreviewDialog(self.printer)
        dialog.setWindowState(Qt.WindowMaximized)
        dialog.paintRequested.connect(self.print_)
        dialog.setWindowFlags(Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowMinMaxButtonsHint | Qt.WindowCloseButtonHint | Qt.WindowContextHelpButtonHint)
        dialog.exec()
开发者ID:Meller008,项目名称:CRM-Avi,代码行数:17,代码来源:print_qt.py

示例12: __init__

    def __init__(self, page_size, print_pdf=False):

        super().__init__(page_size)

        self._printer = QPrinter(QPrinter.HighResolution)
        self._printer.setPageSize(QtGui.QPageSize(QtCore.QSizeF(*page_size),
                                                  QtGui.QPageSize.Millimeter))
        self._printer.setColorMode(QPrinter.Color)

        logging.info('Using printer "%s"', self._printer.printerName())

        self._print_pdf = print_pdf
        if self._print_pdf:
            logging.info('Using PDF printer')
            self._counter = 0
            self._printer.setOutputFormat(QPrinter.PdfFormat)
            self._printer.setFullPage(True)
开发者ID:fuentecilla86,项目名称:photobooth,代码行数:17,代码来源:PrinterPyQt5.py

示例13: print_sheet

    def print_sheet(self):
        printer = QPrinter(QPrinterInfo.defaultPrinter())
        printer.setOutputFileName('foo.pdf')
        printer.setResolution(72)
        printer.setFullPage(True)

        self.webRptView.print(printer)

        pdf = 'foo.pdf'
            
        AcroRD32Path = winreg.QueryValue(winreg.HKEY_CLASSES_ROOT, 'Software\\Adobe\\Acrobat\Exe')
            
        acroread = AcroRD32Path
            
        cmd= '{0} /N /T "{1}" ""'.format(acroread,pdf)  
        proc = subprocess.Popen(cmd)
        time.sleep(5)
           
        os.system('TASKKILL /F /IM AcroRD32.exe')
        os.remove('foo.pdf')   
开发者ID:Ink-Pixi,项目名称:problem_sheet_viewer,代码行数:20,代码来源:report_viewer.py

示例14: process_html

def process_html(htmlpath, args, app):
    
    
    htmlurl = urllib.parse.quote(htmlpath.resolve().absolute().as_posix())
    htmlQurl = QUrl("file://{}".format(htmlurl))
 
    pdfOutputPath = htmlpath.with_suffix(".pdf")
    
    print("htmlpath:", htmlpath)
    print("htmlurl:", htmlurl)
    print("htmlQurl:", htmlQurl)
    print("pdfOutputPath:", pdfOutputPath)
    
    web = QWebView()
    web.page().settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
    
    printer = QPrinter()
    printer.setPageSize(QPrinter.A4)
    printer.setOutputFormat(QPrinter.PdfFormat)
    printer.setOutputFileName(str(pdfOutputPath))
 
    def convertIt():
        web.print_(printer)
        print("Pdf generated")
    
    def closeIt():
        QApplication.exit()
 
    web.loadFinished.connect(convertIt)

    if args.show:
        web.show()
    else:
        web.loadFinished.connect(closeIt)
    
    web.load(htmlQurl)
开发者ID:manasdas17,项目名称:scilab-2,代码行数:36,代码来源:html2pdf.py

示例15: __printPreviewImage

 def __printPreviewImage(self):
     """
     Private slot to handle the Print Preview menu action.
     """
     from PyQt5.QtPrintSupport import QPrintPreviewDialog
     
     if self.mainWidget is None:
         E5MessageBox.critical(
             self,
             self.tr("Print Preview"),
             self.tr("""There is no UI file loaded."""))
         return
     
     settings = Preferences.Prefs.settings
     printer = QPrinter(QPrinter.HighResolution)
     printer.setFullPage(True)
     
     printerName = Preferences.getPrinter("UIPreviewer/printername")
     if printerName:
         printer.setPrinterName(printerName)
     printer.setPageSize(
         QPrinter.PageSize(int(settings.value("UIPreviewer/pagesize"))))
     printer.setPageOrder(
         QPrinter.PageOrder(int(settings.value("UIPreviewer/pageorder"))))
     printer.setOrientation(QPrinter.Orientation(
         int(settings.value("UIPreviewer/orientation"))))
     printer.setColorMode(
         QPrinter.ColorMode(int(settings.value("UIPreviewer/colormode"))))
     
     preview = QPrintPreviewDialog(printer, self)
     preview.paintRequested.connect(self.__print)
     preview.exec_()
开发者ID:Darriall,项目名称:eric,代码行数:32,代码来源:UIPreviewer.py


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