本文整理汇总了Python中PyQt5.QtPrintSupport.QPrinter.setOutputFileName方法的典型用法代码示例。如果您正苦于以下问题:Python QPrinter.setOutputFileName方法的具体用法?Python QPrinter.setOutputFileName怎么用?Python QPrinter.setOutputFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtPrintSupport.QPrinter
的用法示例。
在下文中一共展示了QPrinter.setOutputFileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print_file
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setOutputFileName [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_()
示例2: calibration_pdf
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setOutputFileName [as 别名]
def calibration_pdf(self, image):
printer = QPrinter()
printer.setPaperSize(QSizeF(210, 297), QPrinter.Millimeter)
printer.setResolution(600)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName(self.get_path_to_calibration_file())
printer.setPageMargins(0,0,0,0,6)
painter = QPainter()
painter.begin(printer)
painter.drawImage(553,533, image)
font = QFont('Source Sans Pro', 10, QFont.Bold)
painter.setFont(font)
painter.drawText(254,277, _("Calibration sheet"))
font = QFont('Source Sans Pro', 7, QFont.Bold)
painter.setFont(font)
painter.drawText(600,2077, _("Instructions:"))
font = QFont('Source Sans Pro', 7, QFont.Normal)
painter.setFont(font)
painter.drawText(700, 2177, _("1. Place this paper on a flat and well iluminated surface."))
painter.drawText(700, 2277, _("2. Align your Revealer borderlines to the dashed lines on the top and left."))
painter.drawText(700, 2377, _("3. Press slightly the Revealer against the paper and read the numbers that best "
"match on the opposite sides. "))
painter.drawText(700, 2477, _("4. Type the numbers in the software"))
painter.end()
示例3: PdfConverter
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setOutputFileName [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
示例4: on_click
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setOutputFileName [as 别名]
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)
示例5: __printPdfRequested
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setOutputFileName [as 别名]
def __printPdfRequested(self, frame):
"""
Private slot to handle a print to PDF request.
@param frame reference to the frame to be printed (QWebFrame)
"""
printer = QPrinter(mode=QPrinter.HighResolution)
if Preferences.getPrinter("ColorMode"):
printer.setColorMode(QPrinter.Color)
else:
printer.setColorMode(QPrinter.GrayScale)
printerName = Preferences.getPrinter("PrinterName")
if printerName:
printer.setPrinterName(printerName)
printer.setOutputFormat(QPrinter.PdfFormat)
name = frame.url().path().rsplit('/', 1)[-1]
if name:
name = name.rsplit('.', 1)[0]
name += '.pdf'
printer.setOutputFileName(name)
printDialog = QPrintDialog(printer, self)
if printDialog.exec_() == QDialog.Accepted:
try:
frame.print_(printer)
except AttributeError:
E5MessageBox.critical(
self,
self.tr("eric6 Web Browser"),
self.tr(
"""<p>Printing is not available due to a bug in"""
""" PyQt5. Please upgrade.</p>"""))
return
示例6: printPdf
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setOutputFileName [as 别名]
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)
示例7: filePrintPdf
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setOutputFileName [as 别名]
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)
示例8: toPdf
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setOutputFileName [as 别名]
def toPdf(self, image, n=0):
printer = QPrinter()
printer.setPaperSize(QSizeF(210, 297), QPrinter.Millimeter);
printer.setResolution(600)
printer.setPageMargins(0,0,0,0, QPrinter.Millimeter)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName(self.base_name+self.filename+'.pdf')
printer.setPageMargins(0,0,0,0,6)
painter = QPainter()
painter.begin(printer)
w = int(4958/13)
h = int(7017/13)
size_h = 2022+int(self.calibration_h)
size_v = 1274+int(self.calibration_v)
image = image.scaled(size_h, size_v)
for n in range(3):
painter.fillRect(0, (n*(7017/3)), 4958, 33, Qt.black )
painter.fillRect(0, (n*(7017/3))+3, 4958, 27, Qt.white )
painter.drawImage(553,(n*(7017/3))+533, image)
wpath = QPainterPath()
wpath.addRoundedRect(QRectF(548,(n*(7017/3))+528, size_h+5, size_v+5), 19, 19)
painter.setPen(QPen(Qt.black, 10))
painter.drawPath(wpath)
'''
master public key
qr_mpk = qrcode.make(self.mpk[0])#
painter.drawImage(3453,933, ImageQt(qr_mpk))
painter.setFont(QFont('Din Trek', 18, QFont.Black))
pen = QPen(Qt.black, 127)
painter.setPen(pen)
painter.fillRect(0, 133+(n*(7017/4)), w, 173, Qt.black )
painter.fillRect(0, 133+(n*(7017/4))+3, w-3, 167, Qt.white )
painter.drawText(177, 266 + (n*(7017/4)), 'R')
'''
painter.end()
示例9: exportToPDF
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setOutputFileName [as 别名]
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()
示例10: print_sheet
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setOutputFileName [as 别名]
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')
示例11: PrinterPyQt5
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setOutputFileName [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()
示例12: calibration_pdf
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setOutputFileName [as 别名]
def calibration_pdf(self, image):
printer = QPrinter()
printer.setPaperSize(QSizeF(210, 297), QPrinter.Millimeter);
printer.setResolution(600)
printer.setPageMargins(0,0,0,0, QPrinter.Millimeter)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName(self.base_dir+'calibration.pdf')
painter = QPainter()
painter.begin(printer)
image = image.scaled(self.size[0]*6.68,self.size[1]*6.68)
#tuning
font = QFont('Source Sans Pro', 27, QFont.Black)
painter.setFont(font)
cal_value = 0
for p in range (1,2):
for x in range (2):
for n in range(5):
cal_value+=1
painter.drawImage(254+(x*2296),130+(n*1326),image.scaled(2022+cal_value,1274+cal_value))
painter.drawText(354+(x*2296),270+(n*1326), str(cal_value))
printer.newPage()
painter.end()
示例13: process_html
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setOutputFileName [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)
示例14: toPdf
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setOutputFileName [as 别名]
def toPdf(self, image):
printer = QPrinter()
printer.setPaperSize(QSizeF(210, 297), QPrinter.Millimeter)
printer.setResolution(600)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName(self.get_path_to_revealer_file('.pdf'))
printer.setPageMargins(0,0,0,0,6)
painter = QPainter()
painter.begin(printer)
delta_h = round(image.width()/self.abstand_v)
delta_v = round(image.height()/self.abstand_h)
size_h = 2028+((int(self.calibration_h)*2028/(2028-(delta_h*2)+int(self.calibration_h)))/2)
size_v = 1284+((int(self.calibration_v)*1284/(1284-(delta_v*2)+int(self.calibration_v)))/2)
image = image.scaled(size_h, size_v)
painter.drawImage(553,533, image)
wpath = QPainterPath()
wpath.addRoundedRect(QRectF(553,533, size_h, size_v), 19, 19)
painter.setPen(QPen(Qt.black, 1))
painter.drawPath(wpath)
painter.end()
示例15: PreviewDialog
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setOutputFileName [as 别名]
#.........这里部分代码省略.........
self.preview.setCurrentPage(self.preview.pageCount())
self.updateNavActions()
def _q_setMode(self, action):
if action == self.overviewModeAction:
self.preview.setViewMode(QPrintPreviewWidget.AllPagesView)
self.setFitting(False)
self.fitGroup.setEnabled(False)
self.navGroup.setEnabled(False)
self.pageNumEdit.setEnabled(False)
self.pageNumLabel.setEnabled(False)
elif action == self.facingModeAction:
self.preview.setViewMode(QPrintPreviewWidget.FacingPagesView)
else:
self.preview.setViewMode(QPrintPreviewWidget.SinglePageView)
if action == self.facingModeAction or action == self.singleModeAction:
self.fitGroup.setEnabled(True)
self.navGroup.setEnabled(True)
self.pageNumEdit.setEnabled(True)
self.pageNumLabel.setEnabled(True)
self.setFitting(True)
def _q_print(self):
printDialog = QPrintDialog(self.printer, self)
if printDialog.exec_() == QDialog.Accepted:
self.preview.print_()
self.accept()
def _q_pageSetup(self):
pageSetup = QPageSetupDialog(self.printer, self)
if pageSetup.exec_() == QDialog.Accepted:
# update possible orientation changes
if self.preview.orientation() == QPrinter.Portrait:
self.portraitAction.setChecked(True)
self.preview.setPortraitOrientation()
else:
self.landscapeAction.setChecked(True)
self.preview.setLandscapeOrientation()
def _q_export(self, action):
if exportToWordAvailable and action == self.wordAction:
fileName, _selectedFilter = getSaveFileName(
self, 'export', '',
OpenNumismat.HOME_PATH, self.tr("Word documents (*.doc)"))
if fileName:
self.__exportToWord(self.fileName, fileName)
elif action == self.htmlAction:
fileName, _selectedFilter = getSaveFileName(
self, 'export', '',
OpenNumismat.HOME_PATH, self.tr("Web page (*.htm *.html)"))
if fileName:
self.__exportToHtml(fileName)
elif action == self.pdfAction:
fileName, _selectedFilter = getSaveFileName(
self, 'export', '',
OpenNumismat.HOME_PATH, self.tr("PDF file (*.pdf)"))
if fileName:
self.__exportToPdf(fileName)
@waitCursorDecorator
def __exportToWord(self, src, dst):
word = win32com.client.Dispatch('Word.Application')
doc = word.Documents.Add(src)
doc.SaveAs(dst, FileFormat=0)
doc.Close()
word.Quit()
@waitCursorDecorator
def __exportToHtml(self, fileName):
template = self.templateSelector.currentData()
report = Report.Report(self.model, template, fileName)
self.fileName = report.generate(self.indexes, True)
@waitCursorDecorator
def __exportToPdf(self, fileName):
self.printer.setOutputFormat(QPrinter.PdfFormat)
self.printer.setOutputFileName(fileName)
self.preview.print_()
self.printer.setOutputFormat(QPrinter.NativeFormat)
def _q_previewChanged(self):
self.updateNavActions()
self.updatePageNumLabel()
self.updateZoomFactor()
def _q_zoomFactorChanged(self):
text = self.zoomFactor.lineEdit().text()
try:
factor = float(text.replace('%', ''))
except ValueError:
return
factor = max(1.0, min(1000.0, factor))
self.preview.setZoomFactor(factor / 100.0)
self.zoomFactor.setEditText("%g%%" % factor)
self.setFitting(False)