Qt PDF

Qt PDF 模塊包含用於渲染 PDF 文檔的類和函數。 QPdfDocument class loads a PDF document and renders pages from it according to the options provided by the QPdfDocumentRenderOptions 類。 QPdfPageRenderer class manages a queue that collects all render requests. The QPdfPageNavigator class handles the navigation through a PDF document. The QPdfSearchModel class searches for a string and holds the search results. The QPdfBookmarkModel class holds the table of contents, if present. The QPdfLinkModel holds information about hyperlinks on a page. The QPdfView widget is a complete PDF viewer, and the PDF 查看器 Widget 範例 shows how to use it.

For Qt Quick applications, three kinds of full-featured viewer components are provided. PdfMultiPageView should be your first choice for the most common user experience: flicking through the pages in the entire document. PdfScrollablePageView shows one page at a time, with scrolling; and PdfPageView shows one full page at a time, without scrolling.

The full-featured viewer components are composed of lower-level QML components that can be used separately if you need to write a more customized PDF viewing application: PdfDocument , PdfPageImage , PdfPageNavigator , PdfSelection , PdfSearchModel , PdfLinkModel ,和 PdfBookmarkModel .

If you only need to render page images, without features such as text selection, search and navigation, this module includes a QImageIOHandler plugin that treats PDF as a scalable image format , similar to SVG . You can simply use 圖像 , and set the currentFrame property to the page index that you wish to display. If the PDF file does not render its own background, the image has a transparent background.

使用模塊

使用 Qt 模塊要求直接或透過其它依賴鏈接到模塊庫。一些構建工具為此有貢獻支持,包括 CMake and 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 Platform Notes} {Platform Notes}

許可和歸屬

Qt PDF 在商業許可下是可用的來自 Qt 公司 。此外,它是可用的根據 GNU LGPL (次一般公共許可) 第 3 版 ,或 GNU GPL (一般公共許可) 第 2 版 。見 Qt PDF 許可 進一步瞭解此模塊的有關細節。