Python PyQt5 PDF Viewer GUI Desktop App Using PDF.js Library Full Project For Beginners

Python PyQt5 PDF Viewer GUI Desktop App Using PDF.js Library Full Project For Beginners

 

Welcome folks today in this blog post we will be building pdf viewer gui desktop app using pdf.js library in pyqt5. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to install the following library using the pip command as shown below

 

pip install pyqt5

 

Now we need to download the stable version of pdf.js library from the below link

 

official pdf.js website

 

Just extract it inside your root directory like this

 

 

 

And now just make an app.py file and copy paste the following code

 

app.py

 

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
import os
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView

PDFJS = f"file://{os.path.abspath('./web/viewer.html')}"
print(PDFJS)
PDF = f'file://{"%20".join(sys.argv[1:])}'
print("loading PDF:", PDF)

class Window(QWebEngineView):
    def __init__(self):
        super(Window, self).__init__()
        self.load(QUrl.fromUserInput(f'{PDFJS}?file={PDF}'))

if __name__ == '__main__':

    app = QApplication(sys.argv)
    window = Window()
    window.showMaximized()
    sys.exit(app.exec_())

 

See also  Join 12 Django Python Whatsapp Group Link For Django Developers in 2021 | Python Django Whatsapp Group Links For Python Developers | Whatsapp Group Links For Django Python Programmers

And now if you execute the above script by typing the below command as shown below

 

python app.py sample.pdf

 

So here we are providing the path of the input pdf file inside the command as shown above

Leave a Reply