Skip to content

Instantly share code, notes, and snippets.

@eyllanesc
Created August 4, 2021 17:32
Show Gist options
  • Save eyllanesc/7566bab2f8a91593c460015ee2151717 to your computer and use it in GitHub Desktop.
Save eyllanesc/7566bab2f8a91593c460015ee2151717 to your computer and use it in GitHub Desktop.
PDF Viewer with QtWebEngine
import sys
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
def main():
print(
f"PyQt5 version: {QtCore.PYQT_VERSION_STR}, Qt version: {QtCore.QT_VERSION_STR}"
)
app = QtWidgets.QApplication(sys.argv)
filename, _ = QtWidgets.QFileDialog.getOpenFileName(None, filter="PDF (*.pdf)")
if not filename:
print("please select the .pdf file")
sys.exit(0)
view = QtWebEngineWidgets.QWebEngineView()
settings = view.settings()
settings.setAttribute(QtWebEngineWidgets.QWebEngineSettings.PluginsEnabled, True)
url = QtCore.QUrl.fromLocalFile(filename)
view.load(url)
view.resize(640, 480)
view.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment