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
#1
Hi

I did not yet run any test for displaying html and pdf documents in a QtWidget because I did not yet fount any information on those subjects.

Thanks a lot to anybody giving me a hint on where to find related documentation.

Arbiel
Reply
#2
GUI is not as simple as that. There is a lot involved in even elementary windows.
Perhaps I am not understanding what you are asking.
But would recommend many of the tutorials available on specifically PyQt5
videos: https://www.youtube.com/results?search_query=PyQt5
tutorials: Just google 'PyQt5 tutorials'
Reply
#3
I have an example on github that shows PDF

https://github.com/Axel-Erfurt/Qt5PDFViewer
Reply
#4
Hi Larz60+ and Axel_Erfurt

Thank you for your reply.

I begun to study the script refered to by Axel_Erfurt, but I still need time to understand it.

As for Larz60+'s comment, to go into some more details on what I'm trying to achieve :

At the age of 12 to 17, I had ancien greek at school (but no english). Some years ago, I decided to study ancien greek again, taking advantage of new technologies.

As I had migrated to Ubuntu a little ealier, I coded some interactive scripts using bash shell with yad and zenity. Because of the cumbersomeness of this approach, I decided recently to migrate these scripts and to expand them using PyQt5.

I'm presently creating sort of a repository of my greek dictionnary in recording for each page its first and last entry. To do so, I want to load the pdf file of the page, which can be found in the following adress

'http://www.tabularium.be/bailly/'

and show up a window displaying the page and three entries for the input of
the first word of the page
its last word and
a checkbox to indicate whether or not the last word expands over the following page or pages.


To do so, I had to collate ancien greek characters, which I achieve in creating corresponding strings between each diacriticized or uppercase letter and their matching lowercase counterpart.

Arbiel
Reply
#5
It is not a real pdf, it is an image.
Reply
#6
Hi Axel_Erfurt

Stating that what I want to read is an image and not a pdf file, do you speak of the contents of the page, which is actuallly the image of the corresponding page of the directory and not the coding into pdf of the effective text ?

Any way, do you know how I can extract the image from its pdf wrapping and display it ?
Reply
#7
Hi Axel_Erfurt

I've been able to modify the example you provided me with. I loaded a page from the local directory where I downloaded individually each page of the greek dictionnary.

To read through the internet, I suppose I have to replace «fromUserInput» by something else in the line
self.load(QUrl.fromUserInput(f'{PDFJS}?file={PDF}'))
To record the first and last entries of each page, I'll need to reduce the size of the page window to be able to read them and key them in the PyQt5 dialog. However an icon representing the page appears in the upperleft corner and masks the first entry. Is it possible not to have it appearing ?

Do you know whether it is possible to close the page window with PyQt5 when both words are entered and validated ?

Arbiel
Reply
#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
#9
This is a better PDF for français grec

https://www.areopage.net/nvlexique/Dicti...tament.pdf
Reply
#10
would recommend many of the tutorials available on specifically PyQt5
videos: https://www.youtube.com/results?search_query=PyQt5
Reply


Forum Jump:

User Panel Messages

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