2

I use qwebengineview to load web with simple code

from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings

class WebPreview(QWebEngineView):
    def __init__(self, parent=None):
        super(WebPreview, self).__init__(parent)
        self.settings().setAttribute(QWebEngineSettings.PluginsEnabled, True)

    def preview(self, link):
        self.load(QUrl(link))

My problem is, when loading an online pdf, such as https://www.nature.com/articles/s41524-021-00506-8.pdf the page will become extremly small when I use ctrl+wheel to zoom

check this link

However, if I load any other none-pdf web https://www.google.com/ I can zoom perfectly with ctrl+wheel

system: windows 10 python: python 3.8 pyqt5: 5.15.3 pyqt5-webengine: 5.15.3

hsdsz
  • 21
  • 2
  • Zooming here is not done by the WebEngineView itself, but by PDF.js - and it must miss a parameter or something from WebEngineView to have the Zoom function correctly. I'm on exactly the same issue. – Mitja Dec 01 '21 at 15:18
  • 1
    I just tried it out, in the most recent Qt Version (6.2.2), this issue seems "fixed". Scrolling and Zooming in a PDF in WebEngineView still is quirky, but it is at least usable. – Mitja Dec 02 '21 at 09:24

1 Answers1

-1

This may work:

from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings

class WebPreview(QWebEngineView):
    def __init__(self, parent=None):
        super(WebPreview, self).__init__(parent)
        self.settings().setAttribute(QWebEngineSettings.WebAttribute.PluginsEnabled, True)
        self.settings().setAttribute(QWebEngineSettings.WebAttribute.PdfViewerEnabled, True)

    def preview(self, link):
        self.load(QUrl(link))

And also you can use pyside6.

from PySide6.QtCore import QUrl
from PySide6.QtWidgets import QApplication
from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtWebEngineCore import QWebEngineSettings
import sys

class WebPreview(QWebEngineView):
    def __init__(self, parent=None):
        super(WebPreview, self).__init__(parent)
        self.settings().setAttribute(QWebEngineSettings.WebAttribute.PluginsEnabled, True)
        self.settings().setAttribute(QWebEngineSettings.WebAttribute.PdfViewerEnabled, True)

    def preview(self, link):
        self.load(QUrl(link))

app = QApplication(sys.argv)
window = WebPreview()
window.preview(r"https://www.nature.com/articles/s41524-021-00506-8.pdf")
window.show()
sys.exit(app.exec_())

Preview

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 15 '23 at 14:56