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


Python QPrinter.setPageSize方法代码示例

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


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

示例1: print_file

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

    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,代码行数:23,代码来源:ui_tools.py

示例2: PdfConverter

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageSize [as 别名]
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,代码行数:29,代码来源:webkit.py

示例3: __printPreviewImage

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageSize [as 别名]
 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,代码行数:34,代码来源:UIPreviewer.py

示例4: ReportDialog

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

#.........这里部分代码省略.........
        """
        Checks which button sent a signal. Based on that it either prints all images or just a single specific image.
        """
        if (self.reportOption == 1):
            for model in self.wholeList:
                self.document.setHtml(self.createHtml(model, forPrinting=True))
                self.printer.setOutputFileName(
                    self.savedfiles.parents[0].__str__() + '/' + self.savedfiles.name.replace("Image Name", "") + model.filename.stem + '.pdf')
                self.document.print(self.printer)
        elif (self.reportOption == 0):
            self.document.print(self.printer)

        elif (self.reportOption == 2):
            self.merger = merger()
            for model in self.wholeList:
                self.document.setHtml(self.createHtml(model, forPrinting=True))
                name = self.savedfiles.__str__() + '.pdf'
                print(name)
                self.printer.setOutputFileName(
                    self.savedfiles.parents[0].__str__() + '/' + self.savedfiles.name.replace("Image Name", "") + model.filename.stem + '.pdf')
                self.document.print(self.printer)
                input = open(self.savedfiles.parents[0].__str__() + '/' + self.savedfiles.name.replace("Image Name", "") + model.filename.stem + '.pdf', "rb")
                self.merger.append(input)
                os.remove(self.savedfiles.parents[0].__str__() + '/' + self.savedfiles.name.replace("Image Name", "") + model.filename.stem + '.pdf')

            out = open(name, "wb")
            self.merger.write(out)
            self.merger.close()

    def printerSetup(self):
        """
        Sets up default instructions for printer.
        """
        self.printer.setPageSize(QPrinter.Letter)
        self.printer.setOutputFormat(QPrinter.PdfFormat)
        self.printer.setFullPage(True)
        self.printer.setOutputFileName(str(self.savedfiles)+".pdf")

    def createHtml(self, model, forPrinting):
        """
        Creates html-based report that shows the basic information about the sample.
        """
        # for printing
        if forPrinting:
            html = """
        <html>
            <head>
                <link type="text/css" rel="stylesheet" href="ntm_style.css"/>
            </head>
            <body>
                <p> Image Name: {name} </p> <p> μ: {th}° </p>
                <p>k: {k} </p>
                <p>R^2: {R2} </p>
                <p>σ: {sig}°</p>
                <br>
                <table>
                    <tr>
                        <td> <img src = "data:image/png;base64,{encodedOrgImg}" width = "250", height = "250" /></td>
                        <td> <img src ="data:image/png;base64,{encodedLogScl}" width = "250", height = "250"/></td>
                    </tr>
                    <tr>
                        <td> <img src = "data:image/png;base64,{encodedAngDist}" width = "250", height = "250" /></td>
                        <td> <img src = "data:image/png;base64,{encodedCartDist}" width = "250", height = "250" /></td>
                    </tr>
                </table>
                <p><br><br>
开发者ID:NTMatBoiseState,项目名称:FiberFit,代码行数:70,代码来源:report.py

示例5: PrintHtml

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageSize [as 别名]
class PrintHtml(QtWebKitWidgets.QWebView):
    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,代码行数:20,代码来源:print_qt.py

示例6: __printImage

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageSize [as 别名]
 def __printImage(self):
     """
     Private slot to handle the Print Image menu action.
     """
     if self.mainWidget is None:
         E5MessageBox.critical(
             self,
             self.tr("Print Image"),
             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"))))
     
     printDialog = QPrintDialog(printer, self)
     if printDialog.exec_() == QDialog.Accepted:
         self.statusBar().showMessage(self.tr("Printing the image..."))
         self.__print(printer)
         
         settings.setValue("UIPreviewer/printername", printer.printerName())
         settings.setValue("UIPreviewer/pagesize", printer.pageSize())
         settings.setValue("UIPreviewer/pageorder", printer.pageOrder())
         settings.setValue("UIPreviewer/orientation", printer.orientation())
         settings.setValue("UIPreviewer/colormode", printer.colorMode())
     
     self.statusBar().showMessage(
         self.tr("Image sent to printer..."), 2000)
开发者ID:Darriall,项目名称:eric,代码行数:42,代码来源:UIPreviewer.py

示例7: PrinterPyQt5

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageSize [as 别名]
class PrinterPyQt5(Printer):

    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)

    def print(self, picture):

        if self._print_pdf:
            self._printer.setOutputFileName('print_%d.pdf' % self._counter)
            self._counter += 1

        logging.info('Printing picture')

        picture = picture.scaled(self._printer.paperRect().size(),
                                 QtCore.Qt.KeepAspectRatio,
                                 QtCore.Qt.SmoothTransformation)

        printable_size = self._printer.pageRect(QPrinter.DevicePixel)
        origin = ((printable_size.width() - picture.width()) // 2,
                  (printable_size.height() - picture.height()) // 2)

        painter = QtGui.QPainter(self._printer)
        painter.drawImage(QtCore.QPoint(*origin), picture)
        painter.end()
开发者ID:fuentecilla86,项目名称:photobooth,代码行数:41,代码来源:PrinterPyQt5.py

示例8: process_html

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageSize [as 别名]
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,代码行数:38,代码来源:html2pdf.py

示例9: filePrintPdf

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageSize [as 别名]
 def filePrintPdf(self, fn):
     printer = QPrinter(QPrinter.HighResolution)
     printer.setPageSize(QPrinter.A4)
     printer.setOutputFileName(fn)
     printer.setOutputFormat(QPrinter.PdfFormat)
     self.document().print_(printer)
开发者ID:correosdelbosque,项目名称:lector,代码行数:8,代码来源:textwidget.py

示例10: DataProcessorGuiMain

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

#.........这里部分代码省略.........

        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
        
    def initTestDataWebView(self):
        
        widget = QWidget()
        webView = TestPageWebView()
        
        refreshButton = QPushButton("Refresh")
        
        v1 = QVBoxLayout()
        v1.addWidget(webView)        
        v1.addWidget(refreshButton)     
        widget.setLayout(v1)
        
        ttfont = QFont("Monospace")
        ttfont.setStyleHint(QFont.TypeWriter)
        ttfont.setPointSize(8)
        webView.setFont(ttfont)
        webView.init()
        
        def setitem(testobj):
开发者ID:manasdas17,项目名称:scilab-2,代码行数:70,代码来源:guiprocessor.py

示例11: QApplication

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageSize [as 别名]
#!/usr/bin/env python3

import sys

from PyQt5.QtWidgets import QApplication 
from PyQt5.QtWebKitWidgets import QWebView
from PyQt5.QtPrintSupport import QPrinter
from PyQt5.QtCore import QUrl

app = QApplication(sys.argv)

web = QWebView()
web.load(QUrl("https://en.wikipedia.org/wiki/The_Temptations"))
printer = QPrinter()
printer.setPageSize(QPrinter.Letter)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName("out.pdf")

def convertIt():
    web.print_(printer)
    print ("PDF Created")
    QApplication.exit()

web.loadFinished.connect(convertIt)

app.exec_()
开发者ID:colinbjohnson,项目名称:snippets,代码行数:28,代码来源:render_page.py

示例12: QWebView

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageSize [as 别名]
<!DOCTYPE html>
<html>
<head>
<style>
p.error {
    color: red;
}
</style>
</head>
<body>

<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p class="error">I am different.</p>
<p>This is a paragraph.</p>
<p class="error">I am different too.</p>

</body>
</html>

"""
web = QWebView()
web.setHtml(html)
 
printer = QPrinter()
printer.setPageSize(QPrinter.A4)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName("./provaacazzo.pdf")
web.print_(printer)
app.exit()
开发者ID:jacopoprendin,项目名称:aqueduct,代码行数:32,代码来源:python_to_pdf.py


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