-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdfview_test.py
48 lines (36 loc) · 1.28 KB
/
pdfview_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Source:
# https://python-forum.io/thread-36741-post-155217.html#pid155217 (Axel_Erfurt)
# https://github.com/Axel-Erfurt (Axel Schneider)
import sys
from os import path
from PyQt6.QtCore import QUrl
from PyQt6.QtWidgets import QApplication, QMainWindow
from PyQt6.QtWebEngineWidgets import QWebEngineView
class MainWindow(QMainWindow):
def __init__(self):
super(QMainWindow, self).__init__()
self.setWindowTitle("PDF Viewer")
self.setGeometry(0, 28, 1000, 750)
self.webView = QWebEngineView()
self.webView.settings().setAttribute(
self.webView.settings().WebAttribute.PluginsEnabled, True
)
self.webView.settings().setAttribute(
self.webView.settings().WebAttribute.PdfViewerEnabled, True
)
self.setCentralWidget(self.webView)
def url_changed(self):
self.setWindowTitle(self.webView.title())
def go_back(self):
self.webView.back()
if __name__ == "__main__":
app = QApplication(sys.argv)
win = MainWindow()
win.show()
wd = path.dirname(sys.argv[0])
filepath = "out"
filename = "u1.pdf"
pdf_path = str(path.join(wd, filepath, filename)).replace("\\", "/")
url = QUrl(f"file:///{pdf_path}")
win.webView.setUrl(url)
sys.exit(app.exec())