本文整理汇总了Python中PyQt4.QtGui.QPrinter.setOutputFileName方法的典型用法代码示例。如果您正苦于以下问题:Python QPrinter.setOutputFileName方法的具体用法?Python QPrinter.setOutputFileName怎么用?Python QPrinter.setOutputFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QPrinter
的用法示例。
在下文中一共展示了QPrinter.setOutputFileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exportPDF
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setOutputFileName [as 别名]
def exportPDF(self, view, file_name, width, height):
pdf = QPrinter()
pdf.setOutputFormat(QPrinter.PdfFormat)
pdf.setPrintRange(QPrinter.AllPages)
pdf.setOrientation(QPrinter.Portrait)
pdf.setResolution(QPrinter.HighResolution)
pdf.setPaperSize(QSizeF(width, height), QPrinter.Point)
pdf.setFullPage(True)
pdf.setOutputFileName(file_name)
view.mainFrame().print_(pdf)
QApplication.restoreOverrideCursor()
示例2: save_report
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setOutputFileName [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
示例3: plotPDF
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setOutputFileName [as 别名]
def plotPDF(self, width, height, output_file, units = "pixels", _plotting_object = None):
"""Plots the data specified in the current input file as a page in a
PDF file with the given width and height, writing the output to the
specified output file. The optional units argument specifies the units
used to measure the plot size; by default, pixels are used, but "cm",
"mm" and "in" are also acceptable.
Returns the QPrinter object used to write the file."""
pdf = QPrinter()
pdf.setOutputFormat(QPrinter.PdfFormat)
pdf.setOutputFileName(output_file)
if units == "in":
width = pdf.logicalDpiX() * width
height = pdf.logicalDpiY() * height
elif units == "cm":
width = pdf.logicalDpiX() * (width / 2.54)
height = pdf.logicalDpiY() * (height / 2.54)
elif units == "mm":
width = pdf.logicalDpiX() * (width / 25.4)
height = pdf.logicalDpiY() * (height / 25.4)
elif units != "pixels":
raise BDianaError, "Unknown units specified to plotPDF: %s" % units
pdf.setPaperSize(QSizeF(width, height), QPrinter.DevicePixel)
pdf.setFullPage(True)
return self._plot(width, height, pdf, _plotting_object)[0]
示例4: print_pdf
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setOutputFileName [as 别名]
def print_pdf(self):
if self.deck is not None:
#Setting the printer
printer = QPrinter(QPrinter.HighResolution)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOrientation(getattr(QPrinter, "Portrait"))
printer.setOutputFileName(self.path)
printer.setPaperSize(getattr(QPrinter, self.paper))
printer.setFullPage(True)
guide = self.max_cards()
printer.setOrientation(getattr(QPrinter, guide["orientation"]))
print guide, self.card_size
#Start printing
with QPainter(printer) as paint:
ind = 0
resol = printer.resolution()
for c in self.deck:
c.resize(self.card_size[0], self.card_size[1])
if ind == guide["max"]:
printer.newPage()
ind = 0
col = ind % guide["horizontal"]
fil = ind // guide["horizontal"]
print ind, fil, col
target = QRectF((col)*self.card_size[0]*resol, (fil)*self.card_size[1]*resol,
self.card_size[0]*resol, self.card_size[1]*resol)
self.preview_card(c)
self.scene.render(paint, target=target, source=QRectF(0,0,c.width(),c.height()))
ind += 1
示例5: print_to_pdf
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setOutputFileName [as 别名]
def print_to_pdf(self,
path,
paper_size = (8.5, 11.0),
paper_margins = (0, 0, 0, 0),
paper_units = QPrinter.Inch,
zoom_factor = 1.0,
):
"""Saves page as a pdf file.
See qt4 QPrinter documentation for more detailed explanations
of options.
:param path: The destination path.
:param paper_size: A 2-tuple indicating size of page to print to.
:param paper_margins: A 4-tuple indicating size of each margin.
:param paper_units: Units for pager_size, pager_margins.
:param zoom_factor: Scale the output content.
"""
assert len(paper_size) == 2
assert len(paper_margins) == 4
printer = QPrinter(mode = QPrinter.ScreenResolution)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setPaperSize(QtCore.QSizeF(*paper_size), paper_units)
printer.setPageMargins(*(paper_margins + (paper_units,)))
printer.setFullPage(True)
printer.setOutputFileName(path)
if self.webview is None:
self.webview = QtWebKit.QWebView()
self.webview.setPage(self.page)
self.webview.setZoomFactor(zoom_factor)
self.webview.print_(printer)
示例6: printPage
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setOutputFileName [as 别名]
def printPage(ok):
printer = QPrinter()
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOrientation(QPrinter.Landscape)
printer.setPageMargins(0.1,0.1,0.1,0.1, QPrinter.Millimeter)
printer.setOutputFileName(sys.argv[2])
view.print_(printer)
app.exit()
示例7: writePdf
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setOutputFileName [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)
示例8: __saveAsPDF
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setOutputFileName [as 别名]
def __saveAsPDF( self, fileName ):
" Saves the flowchart as an PDF file "
printer = QPrinter()
printer.setOutputFormat( QPrinter.PdfFormat )
printer.setPaperSize( QSizeF( self.scene.width(),
self.scene.height() ), QPrinter.Point )
printer.setFullPage( True )
printer.setOutputFileName( fileName )
painter = QPainter( printer )
self.scene.render( painter )
painter.end()
return
示例9: WebKitPDF
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setOutputFileName [as 别名]
class WebKitPDF ( QObject ):
def __init__ ( self, url, dest ):
QObject.__init__ ( self )
self.dest = dest
self.page = QtWebKit.QWebPage ( self )
self.mainFrame = self.page.mainFrame()
self.mainFrame.load ( QUrl ( url ) )
# Settings
# Disable the scrollbars
self.mainFrame.setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
self.mainFrame.setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
self.connect ( self.page,
SIGNAL ( "loadProgress(int)" ),
self.loadProgress )
self.connect ( self.page,
SIGNAL ( "loadFinished(bool)" ),
self.renderPDF )
def loadProgress ( self, progress ):
print "Progress: ", progress
def renderPDF ( self, status ):
print "Load finished with status: ", status
print "Rendering PDF ..."
contentsSize = self.mainFrame.contentsSize()
contentsSize.setWidth(1280)
self.page.setViewportSize ( contentsSize )
self.printer = QPrinter ( QPrinter.PrinterResolution )
#self.printer = QPrinter ( QPrinter.ScreenResolution )
self.printer.setOutputFormat ( QPrinter.PdfFormat )
#self.printer.setPaperSize ( QPrinter.A4 )
self.printer.setFullPage( True )
self.printer.setPaperSize ( QSizeF( contentsSize ), QPrinter.DevicePixel )
self.printer.setOrientation ( QPrinter.Portrait )
self.printer.setOutputFileName ( self.dest )
self.painter = QPainter ( self.printer )
self.painter.setRenderHint ( QPainter.Antialiasing )
self.mainFrame.render ( self.painter )
self.painter.end()
app = QtGui.QApplication.instance()
app.exit ( 0 )
示例10: __init__
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setOutputFileName [as 别名]
def __init__(self, parent = None, fakeStartup = False, filename = None):
'''
Constructor
'''
self._fakeStartup = fakeStartup
super(DrumBurp, self).__init__(parent)
self._state = None
self._asciiSettings = None
self._printer = None
self.setupUi(self)
self.scoreScene = None
self.paperBox.blockSignals(True)
self.paperBox.clear()
self._knownPageHeights = []
printer = QPrinter()
printer.setOutputFileName("invalid.pdf")
for name in dir(QPrinter):
attr = getattr(QPrinter, name)
if (isinstance(attr, QPrinter.PageSize)
and name != "Custom"):
self.paperBox.addItem(name)
printer.setPaperSize(attr)
self._knownPageHeights.append(printer.pageRect().height())
self._pageHeight = printer.paperRect().height()
self.paperBox.blockSignals(False)
settings = self._makeQSettings()
self.recentFiles = [unicode(fname) for fname in
settings.value("RecentFiles").toStringList()
if os.path.exists(unicode(fname))]
if filename is None:
filename = (None
if len(self.recentFiles) == 0
else self.recentFiles[0])
self.filename = filename
self.addToRecentFiles()
self.updateRecentFiles()
self.songProperties = QDisplayProperties()
# Create scene
self.scoreScene = QScore(self)
self.restoreGeometry(settings.value("Geometry").toByteArray())
self.restoreState(settings.value("MainWindow/State").toByteArray())
self.statusbar.addPermanentWidget(QFrame())
self.availableNotesLabel = QLabel()
self.availableNotesLabel.setMinimumWidth(250)
self.statusbar.addPermanentWidget(self.availableNotesLabel)
self._infoBar = QLabel()
self.statusbar.addPermanentWidget(self._infoBar)
self._initializeState()
self.setSections()
QTimer.singleShot(0, self._startUp)
self.actionCheckOnStartup.setChecked(settings.value("CheckOnStartup").toBool())
示例11: init_print
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setOutputFileName [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))
示例12: writePdfabs
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setOutputFileName [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)
示例13: printBill
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setOutputFileName [as 别名]
def printBill(self):
self.saveTab() #save before printing so that changes will be added to print
html = self.creator.makePrintfile(self.item)
document = QWebView()
document.setHtml(html)
printer = QPrinter()
printer.setOutputFileName(getBillPath() + str(datetime.datetime.now())[0:-7] + '_' + str(self.item.id) + '.pdf')
printpreview = QPrintDialog(printer, self)
printpreview.exec()
document.print(printer)
示例14: render_pdf
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setOutputFileName [as 别名]
def render_pdf(self, page, fileName, paperSize=None):
"""Renders the page into a pdf
:param page: The webpage that we want to render
:param fileName: The path where we want to save the pdf.
For example /home/user/mypdf.pdf
:param paperSize: An PaperSize object that will be used
to render the webpage
"""
mainFrame = page.currentFrame()
printer = QPrinter()
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName(fileName)
printer.setResolution(self._get_default_dpi())
if paperSize is None:
ps = mainFrame.contentsSize()
paperSize = PaperSize(width=ps.width(),
height=ps.width(),
margin=(0, 0, 0, 0),
orientation=None,
page_type=None)
if paperSize.page_type is not None:
if paperSize.orientation.lower() == "landscape":
orientation = QPrinter.Landscape
else:
orientation = QPrinter.Portrait
printer.setOrientation(orientation)
printer.setPaperSize(QPrinter.A4) # Fallback
for f in self.PAGE_TYPE:
if paperSize.page_type.lower() == f[0].lower():
printer.setPaperSize(f[1])
break
else:
sizePt = QSizeF(paperSize.width,
paperSize.height)
printer.setPaperSize(sizePt, QPrinter.Point)
printer.setPageMargins(paperSize.margin[0],
paperSize.margin[1],
paperSize.margin[2],
paperSize.margin[3],
QPrinter.Point)
mainFrame.print_(printer)
示例15: print_grid
# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setOutputFileName [as 别名]
def print_grid(self):
if self.deck is not None:
#Setting the printer
printer = QPrinter(QPrinter.HighResolution)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOrientation(getattr(QPrinter, self.orientation))
printer.setOutputFileName(self.path)
printer.setPaperSize(getattr(QPrinter, self.paper))
#Start printing
with QPainter(printer) as paint:
first = True
for c in self.deck:
if not first:
printer.newPage()
first = False
self.preview_card(c)
self.scene.render(paint)