Skip to content

Instantly share code, notes, and snippets.

@mwicat
Created January 9, 2022 23:58
Show Gist options
  • Save mwicat/02099ddc024fd0993ee50edb89e9634d to your computer and use it in GitHub Desktop.
Save mwicat/02099ddc024fd0993ee50edb89e9634d to your computer and use it in GitHub Desktop.
import sys
import os
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView
fn = os.path.expanduser('~/tmp/report.pdf')
app = QApplication([])
def pdf_rendered(b):
with open(fn, 'wb') as f:
f.write(b)
app.quit()
def load_finished(ok):
win.page().printToPdf(pdf_rendered)
win = QWebView()
win.loadFinished.connect(load_finished)
url = sys.argv[1]
win.load(QUrl(url))
win.show()
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment