You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PyQt5的QWebEngineView中启用Adobe Reader?

Fixing PDF Viewing with Adobe Reader in PyQt5's QWebEngineView

Hey there! Let's break down why your current code isn't working and walk through the solutions you can try.

The Core Issue: NPAPI Plugin Support is Gone

First off, QWebEngineView is built on Chromium, which removed support for NPAPI plugins (the type Adobe Reader uses) several years ago. That means even if you set PluginsEnabled to True, Chromium won't load the Adobe Reader plugin at all—this setting only applies to the few remaining plugin types Chromium still supports, which don't include Adobe's PDF plugin.

Solution 1: Use QWebEngineView's Built-in PDF Viewer

The easiest and most reliable fix is to use the native PDF viewer that comes with QWebEngineView. It's enabled by default in most recent PyQt5 versions, but you can explicitly enable it to be safe. Here's how to adjust your code:

import sys
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets

app = QtWidgets.QApplication(sys.argv)
web = QtWebEngineWidgets.QWebEngineView()

# Explicitly enable the built-in PDF viewer (optional but recommended for clarity)
web.settings().setAttribute(QtWebEngineWidgets.QWebEngineSettings.PdfViewerEnabled, True)

# Load your PDF file
web.load(QtCore.QUrl('file:///path/to/my/file.pdf'))
web.show()
sys.exit(app.exec_())

This approach is cross-platform (works on Windows, macOS, Linux) and doesn't require any additional software like Adobe Reader to be installed.

Solution 2: Embed Adobe Reader via ActiveX (Windows Only)

If you absolutely need to use Adobe Reader (for specific features like advanced annotation or form filling that the built-in viewer doesn't support), you can embed it using QAxWidget—but this only works on Windows, since it relies on ActiveX controls.

First, make sure Adobe Reader is installed on the system and has ActiveX support enabled. Then use this code:

import sys
from PyQt5 import QtWidgets, QtAxContainer

app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QMainWindow()
container = QtWidgets.QWidget()
window.setCentralWidget(container)
layout = QtWidgets.QVBoxLayout(container)

# Create the Adobe Reader ActiveX widget
adobe_reader = QtAxContainer.QAxWidget()
# Use the control ID for Adobe Reader (try "AcroPDF.PDF" or "PDF.PdfCtrl")
adobe_reader.setControl("AcroPDF.PDF")

# Check if the control was found
if not adobe_reader.isControlValid():
    print("Adobe Reader ActiveX control not found—make sure Adobe Reader is installed and ActiveX is enabled.")
    sys.exit(1)

# Load your PDF file
adobe_reader.dynamicCall("LoadFile(const QString&)", r"C:\path\to\your\file.pdf")

# Add the widget to the layout
layout.addWidget(adobe_reader)
window.show()

sys.exit(app.exec_())

Note that this method is platform-specific and depends on the user having Adobe Reader installed with ActiveX enabled—so it's not ideal for cross-platform apps.

Final Recommendation

Stick with the built-in PDF viewer for most cases—it's simpler, more reliable, and works everywhere. Only use the ActiveX approach if you have a strict requirement for Adobe Reader's specific features.

内容的提问来源于stack exchange,提问作者Tom Aubier

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:57:28