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


Python QPrinter.setPageMargins方法代码示例

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


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

示例1: print_to_pdf

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageMargins [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)
开发者ID:Awesoham,项目名称:Ghost.py,代码行数:33,代码来源:ghost.py

示例2: printPage

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageMargins [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()
开发者ID:anjohnson,项目名称:pvDataWWW,代码行数:10,代码来源:qtweb.py

示例3: init_print

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageMargins [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))
开发者ID:et0803,项目名称:code2pdf,代码行数:16,代码来源:code2pdf.py

示例4: render_pdf

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageMargins [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)
开发者ID:a1939228,项目名称:Ghost.py,代码行数:49,代码来源:pdf.py

示例5: renderPdf

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageMargins [as 别名]
    def renderPdf(self, fileName):
        p = QPrinter()
        p.setOutputFormat(QPrinter.PdfFormat)
        p.setOutputFileName(fileName)
        p.setResolution(pdf_dpi)
        paperSize = self.m_paperSize

        if not len(paperSize):
            pageSize = QSize(self.m_page.mainFrame().contentsSize())
            paperSize['width'] = str(pageSize.width()) + 'px'
            paperSize['height'] = str(pageSize.height()) + 'px'
            paperSize['border'] = '0px'

        if paperSize.get('width') and paperSize.get('height'):
            sizePt = QSizeF(ceil(self.stringToPointSize(paperSize['width'])),
                            ceil(self.stringToPointSize(paperSize['height'])))
            p.setPaperSize(sizePt, QPrinter.Point)
        elif 'format' in paperSize:
            orientation = QPrinter.Landscape if paperSize.get('orientation') and paperSize['orientation'].lower() == 'landscape' else QPrinter.Portrait
            orientation = QPrinter.Orientation(orientation)
            p.setOrientation(orientation)

            formats = {
                'A3': QPrinter.A3,
                'A4': QPrinter.A4,
                'A5': QPrinter.A5,
                'Legal': QPrinter.Legal,
                'Letter': QPrinter.Letter,
                'Tabloid': QPrinter.Tabloid
            }

            p.setPaperSize(QPrinter.A4) # fallback
            for format, size in formats.items():
                if format.lower() == paperSize['format'].lower():
                    p.setPaperSize(size)
                    break
        else:
            return False

        border = floor(self.stringToPointSize(paperSize['border'])) if paperSize.get('border') else 0
        p.setPageMargins(border, border, border, border, QPrinter.Point)

        self.m_page.mainFrame().print_(p)
        return True
开发者ID:10git,项目名称:TheObserver,代码行数:46,代码来源:phantom.py

示例6: print_pdf

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageMargins [as 别名]
def print_pdf(html, filename):
    """ Print HTML to PDF. """

    wv = QWebView()
    wv.setHtml(html)

    # doc = QTextDocument()
    # doc.setHtml(html)

    printer = QPrinter()
    printer.setOutputFileName(filename)
    printer.setOutputFormat(QPrinter.PdfFormat)
    printer.setPageSize(QPrinter.A4)
    printer.setPageMargins(15, 15, 15, 15, QPrinter.Millimeter)

    # doc.print_(printer)
    wv.print_(printer)

    print("PDF Generated: " + filename)
开发者ID:Joisar,项目名称:Python-Scripts,代码行数:21,代码来源:g4g.py

示例7: print_document

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageMargins [as 别名]
def print_document(document, verse_key, pdf = False, copies=1, skip=False):
    printer = QPrinter(QPrinter.HighResolution)

    if not pdf: printer.setOutputFormat(QPrinter.NativeFormat)
    else:
        printer.setOutputFormat(QPrinter.PdfFormat)
        printer.setOutputFileName(ROOT + 'verse.pdf')
    printer.setPaperSize(QPrinter.A4)
    printer.setCopyCount(copies)

    printer.setPageMargins(10, 10, 10, 10, QPrinter.Millimeter)

    doc = QTextDocument()
    doc.setHtml(concatenate_pages(document, verse_key, skip))

    dialog = QPrintPreviewDialog(printer)
    dialog.setWindowFlags(Qt.Window)
    dialog.setWindowTitle('Print preview: parse results')

    def preview(): doc.print_(printer)

    dialog.paintRequested.connect(preview)
    dialog.exec_()
开发者ID:Xifax,项目名称:siteki,代码行数:25,代码来源:printing.py

示例8: main

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageMargins [as 别名]
def main():
	app = QApplication(sys.argv)
	
	# Preparing the pdf
	doc = QTextDocument()
	printer = QPrinter()
	printer.setOutputFileName("KabitGurdas.pdf")
	printer.setOutputFormat(QPrinter.PdfFormat)
	
	# Setting page size as A5
	printer.setPaperSize(QPrinter.A5);
	# page margin
	
	printer.setPageMargins(12, 16, 12, 20, QPrinter.Millimeter)
	doc.setPageSize(QSizeF(printer.pageRect().size()))
	
	painter = QPainter()
	painter.begin( printer )	
	
	# Set poem book and get each poem in pdf
	book = kb()
	
	for KabitNumber in range(1,676):		
		# Add text in html to page
		doc.setHtml(book.getKabitHTML(KabitNumber))
		doc.defaultFont().setPointSize(20)
	
		# A new page
		printer.newPage()
		# Create a QPainter to draw our content    
		doc.drawContents(painter)#,printer.pageRect().translated( -printer.pageRect().x(), -printer.pageRect().y() ))
		#QTextDocument.drawContents(QPainter, QRectF rect=QRectF())
		doc.print_(printer)
	
	# Done.
	painter.end()
开发者ID:rusticmystic,项目名称:kabit_gurdas_bhalla,代码行数:38,代码来源:create_pdf.py

示例9: Ventana_Imprimir

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageMargins [as 别名]
class Ventana_Imprimir(QtGui.QDialog):

    def __init__(self, parent=None, datos=None):

        self.parent = parent
        self.transito = datos
        super(Ventana_Imprimir, self).__init__(parent=self.parent)
        self.setGeometry(30, 40, 800, 500)
        self.setWindowTitle("Imprimir albaran")

        self.init_controles()

        #self.navegador.setUrl(QUrl('http://www.google.es'))
        self.navegador.setHtml(self.leer_plantilla_y_poner_datos())
        #self.navegador.loadFinished.connect(lambda: self.LoadEnd())

    def leer_plantilla_y_poner_datos(self):
        html = open(PLANTILLA_ALBARAN).read()

        if self.transito is None:
            html = """
            <!DOCTYPE html>
            <html lang="es">
            <head>
                <meta charset="UTF-8">
                <title></title>
            </head>
            <body >
                <h1 style='color:red;'>NO HAY DATOS QUE PRESENTAR</h1>
            </body>
            </html>
            """
        else:
            #pongamos los datos
            #self.transito = Historico()
            html = html.replace("@num_albaran", str(self.transito.num_albaran))
            html = html.replace("@mat_cabina", self.transito.mat_cabina)
            html = html.replace("@mat_remolque", self.transito.mat_remolque)

            html = html.replace("@cliente", self.transito.razon_social_cliente)
            html = html.replace("@producto", self.transito.nombre_producto)
            html = html.replace("@proveedor", self.transito.razon_social_proveedor)
            html = html.replace("@poseedor", self.transito.razon_social_poseedor)
            html = html.replace("@agencia", self.transito.razon_social_agencia)
            html = html.replace("@conductor", self.transito.nombre_conductor)
            html = html.replace("@origen", self.transito.origen)
            html = html.replace("@destino", self.transito.destino)
            html = html.replace("@fech_entrada", self.transito.fecha_entrada)
            html = html.replace("@fech_salida", self.transito.fecha_salida)
            html = html.replace("@peso_entrada", str(self.transito.bruto))
            html = html.replace("@peso_salida", str(self.transito.tara))
            html = html.replace("@neto", str(self.transito.neto))

        return html

    def printPreview(self):

        dialog = QtGui.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()

    def imprimir(self):
        print('Prepandando impresion')

        self.printer = QPrinter(QPrinter.HighResolution);
        self.printer.setPageSize(QPrinter.A4);
        self.printer.setOrientation(QPrinter.Portrait);
        self.printer.setPageMargins(10, 10, 10, 10, QPrinter.Millimeter)
        self.navegador.print_(self.printer)

    def LoadEnd(self):

        #self.printer = QPrinter( QPrinter.HighResolution )
        #self.printer.setOutputFormat( QPrinter.PdfFormat )
        #self.printer.setOutputFileName( "out.pdf" )
        #self.printPreview()
        #self.navegador.print_( self.printer )
        pass

    def init_controles(self):
        vbox = QtGui.QVBoxLayout()

        self.navegador = QtWebKit.QWebView(self)
        self.btnImprimir = QtGui.QPushButton(IMPRIMIR, self)
        self.btnImprimir.clicked.connect(lambda: self.imprimir())

        vbox.addWidget(self.btnImprimir)
        vbox.addWidget(self.navegador)

        self.setLayout(vbox)
开发者ID:arkadoel,项目名称:openbascula,代码行数:98,代码来源:Dialogo_impresion.py

示例10: renderPdf

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageMargins [as 别名]
    def renderPdf(self, fileName):
        p = QPrinter()
        p.setOutputFormat(QPrinter.PdfFormat)
        p.setOutputFileName(fileName)
        p.setResolution(pdf_dpi)
        paperSize = self.m_paperSize

        if not len(paperSize):
            pageSize = QSize(self.m_webPage.mainFrame().contentsSize())
            paperSize['width'] = str(pageSize.width()) + 'px'
            paperSize['height'] = str(pageSize.height()) + 'px'
            paperSize['border'] = '0px'

        if paperSize.get('width') and paperSize.get('height'):
            sizePt = QSizeF(ceil(self.stringToPointSize(paperSize['width'])),
                            ceil(self.stringToPointSize(paperSize['height'])))
            p.setPaperSize(sizePt, QPrinter.Point)
        elif 'format' in paperSize:
            orientation = QPrinter.Landscape if paperSize.get('orientation') and paperSize['orientation'].lower() == 'landscape' else QPrinter.Portrait
            orientation = QPrinter.Orientation(orientation)
            p.setOrientation(orientation)

            formats = {
                'A0': QPrinter.A0,
                'A1': QPrinter.A1,
                'A2': QPrinter.A2,
                'A3': QPrinter.A3,
                'A4': QPrinter.A4,
                'A5': QPrinter.A5,
                'A6': QPrinter.A6,
                'A7': QPrinter.A7,
                'A8': QPrinter.A8,
                'A9': QPrinter.A9,
                'B0': QPrinter.B0,
                'B1': QPrinter.B1,
                'B2': QPrinter.B2,
                'B3': QPrinter.B3,
                'B4': QPrinter.B4,
                'B5': QPrinter.B5,
                'B6': QPrinter.B6,
                'B7': QPrinter.B7,
                'B8': QPrinter.B8,
                'B9': QPrinter.B9,
                'B10': QPrinter.B10,
                'C5E': QPrinter.C5E,
                'Comm10E': QPrinter.Comm10E,
                'DLE': QPrinter.DLE,
                'Executive': QPrinter.Executive,
                'Folio': QPrinter.Folio,
                'Ledger': QPrinter.Ledger,
                'Legal': QPrinter.Legal,
                'Letter': QPrinter.Letter,
                'Tabloid': QPrinter.Tabloid
            }

            p.setPaperSize(QPrinter.A4) # fallback
            for format, size in formats.items():
                if format.lower() == paperSize['format'].lower():
                    p.setPaperSize(size)
                    break
        else:
            return False

        border = floor(self.stringToPointSize(paperSize['border'])) if paperSize.get('border') else 0
        p.setPageMargins(border, border, border, border, QPrinter.Point)

        self.m_webPage.mainFrame().print_(p)
        return True
开发者ID:capetown,项目名称:phantomjs,代码行数:70,代码来源:webpage.py

示例11: QApplication

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageMargins [as 别名]
from PyQt4.QtGui import QTextDocument, QPrinter, QApplication
import sys

app = QApplication(sys.argv)

doc = QTextDocument()
location = sys.argv[1]
html = open(location).read()
doc.setHtml(html)

printer = QPrinter()
printer.setOutputFileName(sys.argv[2])
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setPageSize(QPrinter.A4)
printer.setPageMargins(15,15,15,15,QPrinter.Millimeter);

doc.print_(printer)
print "\n" + sys.argv[2] + " was created successfully.\n"
开发者ID:connorkendrick,项目名称:html-pdf-gen,代码行数:20,代码来源:pdfgen.py

示例12: QTextDocument

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageMargins [as 别名]
# SHortcuts for languages
Pun = u"punjabi"
Hin = u"hindi"
Tr = u"english"
Ro = u"roman"

# Preparing the pdf
doc = QTextDocument()

printer = QPrinter()
printer.setOutputFileName("KabitGurdas2.pdf")
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setPaperSize(QPrinter.A4)
# page margin

printer.setPageMargins(12, 16, 12, 20, QPrinter.Millimeter)
doc.setPageSize(QSizeF(printer.pageRect().size()))

# We have a database of 675 kabits
KabitRange = range(1, 676)
html = [1] * KabitRange.__len__()
ch = [1] * KabitRange.__len__()

count = 0

painter = QPainter()
painter.begin(printer)

for KabitNumber in KabitRange:
    # 	print KabitNumber
    Plist = GetKabitTextList(KabitNumber, Pun)
开发者ID:rusticmystic,项目名称:demo_sources,代码行数:33,代码来源:kabit_pdf.py

示例13: open

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageMargins [as 别名]
  <body>
    {table}
  </body>
</html>.
'''
with open('_tmp_results.html', 'w') as f:
    f.write(html_string.format(table=df.to_html(
                    classes='mystyle',
                    index=False,
                    float_format='%.1f',
                    # Case by case specific formatting:
                    formatters={'Max UR Line1': lambda x: '%.2f' % x})))


# Create a document and print it to pdf
doc = QTextDocument()
location = '_tmp_results.html'
html = open(location).read()
doc.setHtml(html)
printer = QPrinter()
printer.setOutputFileName('results.pdf')
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setPageSize(QPrinter.A3)
printer.setOrientation(QPrinter.Landscape)
printer.setPageMargins(10, 10, 10, 10, QPrinter.Millimeter)
doc.print_(printer)

# Clean up
os.remove('_tmp_df_style.css')
os.remove('_tmp_results.html')
开发者ID:haphaeu,项目名称:yoshimi,代码行数:32,代码来源:dataframe2pdf.py

示例14: renderPdf

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import setPageMargins [as 别名]
    def renderPdf(self, fileName):
        p = QPrinter()
        p.setOutputFormat(QPrinter.PdfFormat)
        p.setOutputFileName(fileName)
        p.setResolution(self.pdf_dpi)
        paperSize = self.m_paperSize

        if not len(paperSize):
            pageSize = QSize(self.m_webPage.mainFrame().contentsSize())
            paperSize["width"] = str(pageSize.width()) + "px"
            paperSize["height"] = str(pageSize.height()) + "px"
            paperSize["border"] = "0px"

        if paperSize.get("width") and paperSize.get("height"):
            sizePt = QSizeF(
                ceil(self.stringToPointSize(paperSize["width"])), ceil(self.stringToPointSize(paperSize["height"]))
            )
            p.setPaperSize(sizePt, QPrinter.Point)
        elif "format" in paperSize:
            orientation = (
                QPrinter.Landscape
                if paperSize.get("orientation") and paperSize["orientation"].lower() == "landscape"
                else QPrinter.Portrait
            )
            orientation = QPrinter.Orientation(orientation)
            p.setOrientation(orientation)

            formats = {
                "A0": QPrinter.A0,
                "A1": QPrinter.A1,
                "A2": QPrinter.A2,
                "A3": QPrinter.A3,
                "A4": QPrinter.A4,
                "A5": QPrinter.A5,
                "A6": QPrinter.A6,
                "A7": QPrinter.A7,
                "A8": QPrinter.A8,
                "A9": QPrinter.A9,
                "B0": QPrinter.B0,
                "B1": QPrinter.B1,
                "B2": QPrinter.B2,
                "B3": QPrinter.B3,
                "B4": QPrinter.B4,
                "B5": QPrinter.B5,
                "B6": QPrinter.B6,
                "B7": QPrinter.B7,
                "B8": QPrinter.B8,
                "B9": QPrinter.B9,
                "B10": QPrinter.B10,
                "C5E": QPrinter.C5E,
                "Comm10E": QPrinter.Comm10E,
                "DLE": QPrinter.DLE,
                "Executive": QPrinter.Executive,
                "Folio": QPrinter.Folio,
                "Ledger": QPrinter.Ledger,
                "Legal": QPrinter.Legal,
                "Letter": QPrinter.Letter,
                "Tabloid": QPrinter.Tabloid,
            }

            p.setPaperSize(QPrinter.A4)  # fallback
            for format_, size in formats.items():
                if format_.lower() == paperSize["format"].lower():
                    p.setPaperSize(size)
                    break
        else:
            return False

        border = floor(self.stringToPointSize(paperSize["border"])) if paperSize.get("border") else 0
        p.setPageMargins(border, border, border, border, QPrinter.Point)

        self.m_webPage.mainFrame().print_(p)
        return True
开发者ID:schmurfy,项目名称:phantomjs,代码行数:75,代码来源:webpage.py


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