本文整理汇总了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_()
示例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)
示例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
示例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)
示例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
示例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
示例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)
示例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()
示例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
示例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()
示例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()
示例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)
示例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')
示例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)
示例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_()