Skip to content

Instantly share code, notes, and snippets.

@zoghal
Forked from jmaupetit/ghost_capture_pdf.py
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoghal/47ca6fcacc69f9f32825 to your computer and use it in GitHub Desktop.
Save zoghal/47ca6fcacc69f9f32825 to your computer and use it in GitHub Desktop.
from ghost import Ghost
from PySide.QtGui import QApplication, QImage, QPainter, QPrinter
class MyGhost(Ghost):
def capture_pdf(self):
printer = QPrinter(QPrinter.HighResolution)
printer.setResolution(300)
printer.setOutputFileName("QtPrinter.pdf")
printer.setPaperSize(QPrinter.A4)
printer.setOrientation(QPrinter.Landscape)
printer.setOutputFormat(QPrinter.PdfFormat)
painter = QPainter(printer)
self.main_frame.render(painter)
painter.end()
ghost = MyGhost(viewport_size=(1280,960))
page, resources = ghost.open('http://127.0.0.1:8000/path/to/page/to/capture/')
ghost.capture_pdf()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment