- 
      
- 
        Save genothomas/09f1f68c28066e8c96b74d6982ef7818 to your computer and use it in GitHub Desktop. 
Revisions
- 
        glowinthedark revised this gist Sep 20, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewingThis file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ # # PDF.js # ============ # only the `web` and `build` folders are required from the the pdfjs project: # git clone --depth 1 https://github.com/mozilla/pdf.js ~/js/pdfjs 
- 
        glowinthedark revised this gist Sep 19, 2021 . 1 changed file with 12 additions and 2 deletions.There are no files selected for viewingThis file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,8 +7,18 @@ from PyQt5.QtWebEngineWidgets import * from PyQt5.QtWidgets import * # REQUIREMENTS # # PyQt5 # ============= # pip3 install PyQt5 # pip3 install PyQtWebEngine # # PDF.js # ============ # only the `web` folder is required from the the pdfjs project: # git clone --depth 1 https://github.com/mozilla/pdf.js ~/js/pdfjs PDFJS = f'file://{Path.home()}/js/pdfjs/web/viewer.html' 
- 
        glowinthedark created this gist Sep 19, 2021 .There are no files selected for viewingThis file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ #!/usr/bin/env python3 import sys from pathlib import Path from PyQt5.QtCore import * from PyQt5.QtWebEngineWidgets import * from PyQt5.QtWidgets import * # REQUIRED: download the pdfjs project: # git clone https://github.com/mozilla/pdf.js ~/js/pdfjs PDFJS = f'file://{Path.home()}/js/pdfjs/web/viewer.html' class QWebView(QWebEngineView): def __init__(self, parent=None, url=None): QWebEngineView.__init__(self) self.current_url = '' if url: self.load(QUrl.fromUserInput(f'{PDFJS}?file={url}')) self.loadFinished.connect(self._on_load_finished) def _on_load_finished(self): print("Url Loaded") class PDFBrother(QMainWindow): def __init__(self, parent=None, args=None): super(PDFBrother, self).__init__(parent) self.create_menu() self.path = len(args) > 1 and args[1] or None self.add_web_widget() self.show() def create_menu(self): self.main_menu = self.menuBar() self.main_menu_actions = {} self.file_menu = self.main_menu.addMenu("File") icon = self.style().standardIcon(QStyle.StandardPixmap.SP_FileDialogStart) self.actionOpen = QAction(icon,"Open", self) self.actionOpen.triggered.connect(self.onOpen) self.file_menu.addAction(self.actionOpen) def add_web_widget(self): self.web_widget = QWebView(self, url=self.path) self.setCentralWidget(self.web_widget) def onOpen(self): path = QFileDialog.getOpenFileName( self, 'Select file', str(Path.home()/'Books'), 'PDF files (*.pdf)') self.web_widget.load(QUrl.fromUserInput(f'{PDFJS}?file={path[0]}')) if __name__ == "__main__": app = QApplication(sys.argv) window = PDFBrother(args=sys.argv) window.setGeometry(600, 50, 800, 600) sys.exit(app.exec_())