Created
August 4, 2021 17:32
-
-
Save eyllanesc/7566bab2f8a91593c460015ee2151717 to your computer and use it in GitHub Desktop.
PDF Viewer with QtWebEngine
This file contains 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 | |
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