I am trying to view a pdf file with QtWebEngineWidgets but I get "your file was not found" in the window. First time trying QtWebEngineWidgets. Please see the result in pic below.
import os
import sys
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
PDFJS = QtCore.QUrl.fromLocalFile(os.path.join(CURRENT_DIR, "pdfjs/web/viewer.html")).toString()
class PdfReport(QtWebEngineWidgets.QWebEngineView):
def load_pdf(self, filename):
url = QtCore.QUrl.fromLocalFile(filename).toString()
self.load(QtCore.QUrl.fromUserInput("%s?file=%s" % (PDFJS, url)))
def sizeHint(self):
return QtCore.QSize(640, 480)
class Foo(QtWidgets.QWidget):
def __init__(self, parent=None):
super(Foo, self).__init__(parent)
self.pdf = PdfReport()
filename = "summary_equipment_evaluation.pdf"
self.pdf.load_pdf(filename)
lay = QtWidgets.QVBoxLayout(self)
lay.addWidget(self.pdf)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = Foo()
w.show()
sys.exit(app.exec_())
UPDATE: After downloading pdfjs, I get this empty window: