Python Forum
[PyQt] Displaying html and pdf in a QtWidget - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [PyQt] Displaying html and pdf in a QtWidget (/thread-31313.html)

Pages: 1 2


Displaying html and pdf in a QtWidget - arbiel - Dec-03-2020

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


RE: Displaying html and pdf in a QtWidget - Larz60+ - Dec-03-2020

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'


RE: Displaying html and pdf in a QtWidget - Axel_Erfurt - Dec-03-2020

I have an example on github that shows PDF

https://github.com/Axel-Erfurt/Qt5PDFViewer


RE: Displaying html and pdf in a QtWidget - arbiel - Dec-06-2020

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


RE: Displaying html and pdf in a QtWidget - Axel_Erfurt - Dec-06-2020

It is not a real pdf, it is an image.


RE: Displaying html and pdf in a QtWidget - arbiel - Dec-06-2020

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 ?


RE: Displaying html and pdf in a QtWidget - arbiel - Dec-06-2020

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


RE: Displaying html and pdf in a QtWidget - Axel_Erfurt - Dec-06-2020

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_())



RE: Displaying html and pdf in a QtWidget - Axel_Erfurt - Dec-06-2020

This is a better PDF for français grec

https://www.areopage.net/nvlexique/DictionnaireGrecFrancaisNouveauTestament.pdf


RE: Displaying html and pdf in a QtWidget - singletonamos50 - Dec-13-2020

would recommend many of the tutorials available on specifically PyQt5
videos: https://www.youtube.com/results?search_query=PyQt5