Created
January 9, 2022 23:58
-
-
Save mwicat/02099ddc024fd0993ee50edb89e9634d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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