Created
January 9, 2012 22:36
-
-
Save creotiv/1585360 to your computer and use it in GitHub Desktop.
WebKit(PyQt4) PDF Printer example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
from PyQt4.QtCore import * | |
from PyQt4.QtGui import * | |
from PyQt4.QtWebKit import * | |
app = QApplication(sys.argv) | |
class htmlViewer(QWebView): | |
def __init__(self,url, parent=None): | |
QWebView.__init__(self,parent) | |
self.setZoomFactor(1) | |
self.setUrl(QUrl(url)) | |
self.printer = QPrinter(QPrinterInfo.defaultPrinter(),QPrinter.HighResolution) | |
self.printer.setOutputFormat(QPrinter.PdfFormat) | |
self.printer.setOrientation(QPrinter.Portrait) | |
self.printer.setPaperSize(QPrinter.A4) | |
self.printer.setFullPage(True) | |
#self.printer.setResolution(72) | |
self.printer.setOutputFileName("printYou.pdf") | |
self.loadFinished.connect(self.execpreview) | |
def execpreview(self,arg): | |
self.print_(self.printer) | |
a = htmlViewer("http://habrahabr.ru/") | |
a.show() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment