mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Ebook Viewer: Support for printing entire book
This commit is contained in:
parent
3a3a05be79
commit
38c92339bb
@ -307,17 +307,47 @@ class DocumentView(QWebView):
|
|||||||
def goto_bookmark(self, bm):
|
def goto_bookmark(self, bm):
|
||||||
self.document.goto_bookmark(bm)
|
self.document.goto_bookmark(bm)
|
||||||
|
|
||||||
|
def all_content(self):
|
||||||
|
book_content = ''
|
||||||
|
|
||||||
|
if self.manager is not None:
|
||||||
|
for path in self.manager.iterator.spine:
|
||||||
|
html = open(path, 'rb').read().decode(path.encoding)
|
||||||
|
book_content += EntityDeclarationProcessor(html).processed_html
|
||||||
|
base_url = QUrl.fromLocalFile(self.manager.iterator.spine[0])
|
||||||
|
else:
|
||||||
|
book_content = self.page().mainFrame().toHtml()
|
||||||
|
base_url = QUrl.fromLocalFile(self.path())
|
||||||
|
|
||||||
|
return (book_content, base_url)
|
||||||
|
|
||||||
def print_preview(self):
|
def print_preview(self):
|
||||||
|
print_view = QWebView()
|
||||||
|
book_content, base_url = self.all_content()
|
||||||
|
print_view.setHtml(book_content, base_url)
|
||||||
|
print_view.setTextSizeMultiplier(self.textSizeMultiplier())
|
||||||
|
|
||||||
|
def finished(ok):
|
||||||
printer = QPrinter(QPrinter.HighResolution)
|
printer = QPrinter(QPrinter.HighResolution)
|
||||||
printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch)
|
printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch)
|
||||||
|
|
||||||
previewDialog = QPrintPreviewDialog(printer, self)
|
previewDialog = QPrintPreviewDialog(printer, self)
|
||||||
|
|
||||||
self.connect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), self.print_)
|
self.connect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), print_view.print_)
|
||||||
previewDialog.exec_()
|
previewDialog.exec_()
|
||||||
self.disconnect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), self.print_)
|
self.disconnect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), print_view.print_)
|
||||||
|
|
||||||
|
self.disconnect(print_view, SIGNAL('loadFinished(bool)'), finished)
|
||||||
|
|
||||||
|
self.connect(print_view, SIGNAL('loadFinished(bool)'), finished)
|
||||||
|
|
||||||
def print_book(self):
|
def print_book(self):
|
||||||
|
print_view = QWebView()
|
||||||
|
book_content, base_url = self.all_content()
|
||||||
|
print_view.setHtml(book_content, base_url)
|
||||||
|
print_view.setTextSizeMultiplier(self.textSizeMultiplier())
|
||||||
|
|
||||||
|
def finished(ok):
|
||||||
printer = QPrinter(QPrinter.HighResolution)
|
printer = QPrinter(QPrinter.HighResolution)
|
||||||
printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch)
|
printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch)
|
||||||
|
|
||||||
@ -326,7 +356,11 @@ class DocumentView(QWebView):
|
|||||||
|
|
||||||
printDialog.exec_()
|
printDialog.exec_()
|
||||||
if printDialog.result() == QDialog.Accepted:
|
if printDialog.result() == QDialog.Accepted:
|
||||||
self.print_(printer)
|
print_view.print_(printer)
|
||||||
|
|
||||||
|
self.disconnect(print_view, SIGNAL('loadFinished(bool)'), finished)
|
||||||
|
|
||||||
|
self.connect(print_view, SIGNAL('loadFinished(bool)'), finished)
|
||||||
|
|
||||||
def config(self, parent=None):
|
def config(self, parent=None):
|
||||||
self.document.do_config(parent)
|
self.document.do_config(parent)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user