Python Forum
[PyQt] Displaying html and pdf in a QtWidget
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Displaying html and pdf in a QtWidget
#8
replace the content of myPDFViewer.py with

import sys
import os
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView
import requests

url = "http://www.tabularium.be/bailly/0001.pdf"

content = requests.get(url).content

with open("/tmp/test.pdf", 'wb') as f:
    f.write(content)

PDFJS = f"file://{os.path.abspath('./web/viewer.html')}"
print(PDFJS)
PDF = "file:///tmp/test.pdf"
print("loading PDF:", PDF)

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

if __name__ == '__main__':

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


Messages In This Thread
Displaying html and pdf in a QtWidget - by arbiel - Dec-03-2020, 08:35 PM
RE: Displaying html and pdf in a QtWidget - by Axel_Erfurt - Dec-06-2020, 06:02 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020