I use PyQt5.QtWebEngineWidgets
with PDF.js
to display pdf files. Is it possible to connect the rendering state of the page to the PyQt5.QtWebEngineWidgets
, so that another function is run, when rendering is complete?
Edit:
I tried different solutions, e.g. the solution given here. Unfortunately I can't find a solution how to connect the solutions described there with my PyQt5.QWebEngineView
.
The way I tried: I added a new class function called rendering_state
to my QWebEngineView
. When the rendering is done (solution from here), I want get the notification that the rendering is complete so that I can later insert another function there. Unfortunately, I don't get an notification, I only get the warning js: Uncaught ReferenceError: renderContext is not defined
. I just don't know from where I get the renderContext
variable
The function I added is this:
def rendering_state(self):
js_script = """
var page = PDFViewerApplication.pdfViewer.currentPageNumber;
//Step 1: store a refer to the renderer
var pageRendering = page.render(renderContext);
//Step : hook into the pdf render complete event
var completeCallback = pageRendering.internalRenderTask.callback;
pageRendering.internalRenderTask.callback = function (error) {
//Step 2: what you want to do before calling the complete method
completeCallback.call(this, error);
//Step 3: do some more stuff
alert("done");
};
"""
self.page().runJavaScript(js_script)
I run the function on my QWebEngineView
like this:
webView = MyWebView()
webView.load(QUrl.fromUserInput('%s?file=%s' % (PDFJS, PDF)))
webView.rendering_state()
Is it the right approach to add a class function and run, after QWebEngineView
is initiated?