PDF file not showing in wx.html2.WebView

Hello everyone.
I have a small build in wxPython and everything is going well. I have a window that must load some pdf files. I use the wx.html2.WebView control. When compiled from the Visual Studio Code IDE, the application works correctly, I can view the pdf correctly. Here the code:

self.vistaPDF=wx.html2.WebView.New(self.panel, pos=(525, 15), size=(555, 545))
self.vistaPDF.LoadURL(file.pdf)

But, when I generate the executable exe with pyinstaller, the pdf file is no longer displayed when executed. What it does is load the “windows file download” window and thus be able to open it from the browser. The PC where it will work is Windows 10 and already has Windows Edge WebView Runtime installed. Reviewing, when the exe file is executed it does not look for the Edge browser, but for Internet Explorer 11 and that is why it is no longer displayed within my own GUI. On the web, I saw that they recommend the following: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
But I see that it still indicates IE. Then I found that I have to modify the backend of Edge (Chromium) so that it ignores IE, but here if I need help, why I don’t know how to implement that part, in code it should be like this:

self.browser = wx.html2.WebView.New(self, backend=wx.html2.WebViewBackendEdge)

But it has no effect. Another alternative would be to use the PyMuPDF library, but that converts the PDF to an image and that will probably be slower with large files. Did anyone have the same problem with Edge (Chromium) backend?
Thanks.

1 Like

You can try this code:

import wx
import wx.html2

class MyFrame(wx.Frame):
    def __init__(self, *args, **kw):
        super().__init__(*args, **kw)
        self.panel = wx.Panel(self)
        
        # Use Edge backend for WebView on Windows
        if wx.Platform == "__WXMSW__":
            self.pdf_viewer = wx.html2.WebView.New(self.panel, backend=wx.html2.WebViewBackendEdge, pos=(525, 15), size=(555, 545))
        else:
            self.pdf_viewer = wx.html2.WebView.New(self.panel, pos=(525, 15), size=(555, 545))
        
        self.pdf_viewer.LoadURL("file.pdf")

app = wx.App(False)
frame = MyFrame(None, title="PDF Viewer")
frame.Show()
app.MainLoop()

hello. Thanks for your answer.
When you have the attribute: backend=wx.html2.WebViewBackendEdge the control is not created.
Without control:
The pdf is not displayed, but a download window appears.

Adding the code you suggest, I showed that if you enter the if, but the control is not created:

but from the Visual Studio Code IDE it works perfectly.

I don’t know what other option I have. Consider that the app runs on Windows 10. That’s why I don’t know why it always tries to open it in IE 11.
Thanks for the help

The attached script works well for me with Edge.
test.zip (612.7 KB)

Here is my configuration:

  • Windows 10
  • Python 3.11.6
  • wxPython 4.2.2a1
  • wxWidgets 3.2.3

I also compiled the script with cx_freeze without any problems.

Regards