Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1320

PDF rendering via QWebEngineView displays a gray rectangle

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 5.15.0
    • PySide
    • None
    • MacOS, Python 3.7.6, PyQt5 5.15.0, PyQt5-sip 12.8.0, PyQtWebEngine 5.15.0, PySide2 5.15.0
    • macOS

    Description

      I'm writing a PyQt5 MDI application. All I want to do is render a PDF in a window, preferably in a QWebEngineView, which is apparently the recommended way to do it.

      No matter what I try, all I get is a gray rectangle.

      Things I've tried:

      • I've tried different PDFs with different content and file sizes.
      • I've tried local PDFs (file://) and remote PDFs (https://), setting the base URL accordingly.
      • I've tried rendering PDFs directly (via load()) and rendering HTML documents with a PDF embedded in an iframe (via setHtml()).
      • I've tried setting various combinations of the following parameters to True: PluginsEnabled, PdfViewerEnabled, WebGLEnabled, Accelerated2dCanvasEnabled, AllowRunningInsecureContent, LocalContentCanAccessFileUrls, LocalContentCanAccessRemoteUrls, AllowWindowActivationFromJavaScript.
      • I've tried moving the local PDF to different locations and setting its permissions to 777. 

      Every time, same result: gray rectangle, no rendered content.

      If the PDF is embedded in an HTML document with other content, then the rest of the content loads perfectly fine, including embedded PNGs. If the PDF is embedded with a particular size, then the gray rectangle is of the appropriate size.

      Clearly, the QWebEngineView is trying to render the PDF:

      • The gray rectangle only appears if the URL correctly identifies an accessible PDF; a bad URL leads to various "file not found" results.
      • I can right-click on the gray rectangle and select Refresh, and the gray rectangle blinks briefly like the page is being reloaded - but the result is another gray rectangle.
      • Right-clicking on the gray rectangle produces other context menu options, including Back, Forward, Save Page, and View Source, which might be appropriate for an actually-loaded PDF. The first two are disabled (since there isn't any navigation history, just the current page) and the second two do nothing.

      I've also opened a Stack Overflow request for info, which has the code for my application:

      https://stackoverflow.com/questions/62226152/pyqt5-qwebengineview-fails-to-render-pdf-embedded-in-html

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            sfsdfd David Stein
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes