Qt PDF
Qt PDF 模块包含用于渲染 PDF 文档的类和函数。QPdfDocument 类加载 PDF 文档,并根据QPdfDocumentRenderOptions 类提供的选项渲染其中的页面。QPdfPageRenderer 类管理一个收集所有渲染请求的队列。QPdfPageNavigator 类处理 PDF 文档的导航。QPdfSearchModel 类搜索字符串并保存搜索结果。QPdfBookmarkModel 类保存目录(如果有)。QPdfLinkModel 保存页面上的超链接信息。QPdfView 小工具是一个完整的 PDF 浏览器,PDF 浏览器小工具示例展示了如何使用它。
对于Qt Quick 应用程序,我们提供了三种全功能查看器组件。对于最常见的用户体验:在整个文档中翻阅页面,PdfMultiPageView 应该是您的首选。PdfScrollablePageView 每次显示一页,并滚动;PdfPageView 每次显示一整页,不滚动。
全功能查看器组件由较低级别的 QML 组件组成,如果您需要编写更个性化的 PDF 查看应用程序,可以单独使用这些组件:PdfDocument这些组件可单独使用: ,PdfPageImage,PdfPageNavigator,PdfSelection,PdfSearchModel,PdfLinkModel, 以及PdfBookmarkModel 。
如果您只需要渲染页面图像,而不需要文本选择、搜索和导航等功能,本模块包含一个QImageIOHandler 插件,可将 PDF 视为类似SVG 的可缩放图像格式。您只需使用图像,并将currentFrame 属性设置为您希望显示的页面索引即可。如果 PDF 文件没有渲染自己的背景,则图像具有透明背景。
使用模块
使用 Qt 模块需要直接或通过其他依赖项链接模块库。有几种构建工具为此提供了专门支持,包括CMake和qmake。
使用 CMake 构建
使用find_package()
命令在Qt6
软件包中找到所需的模块组件:
find_package(Qt6 REQUIRED COMPONENTS Pdf) target_link_libraries(mytarget Qt6::Pdf)
另请参阅使用 CMake 构建概述。
使用 qmake 构建
要链接模块,请在 qmake 项目文件中添加此行:
QT += pdf
示例
API 参考
文章和指南
许可证和归属
Qt PDF 本软件可在The Qt Company 的商业许可下使用。此外,它还可以在GNU Lesser General Public License 第 3 版或GNU General Public License 第 2 版下使用。有关该模块的更多详情,请参阅Qt PDF Licensing。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.