QPdfDocument 類加載 PDF 文檔並渲染其頁麵。 更多...
| 頭: |
#include <QPdfDocument>
|
| 繼承: | QObject |
| 枚舉類 | Error { None, Unknown, DataNotYetAvailable, FileNotFound, InvalidFileFormat, …, UnsupportedSecurityScheme } |
| 枚舉類 | MetaDataField { Title, Author, Subject, Keywords, Creator, …, ModificationDate } |
| 枚舉類 | PageModelRole { Label, PointSize } |
| 枚舉類 | Status { Null, Loading, Ready, Unloading, Error } |
| QPdfDocument (QObject * parent ) | |
| virtual | ~QPdfDocument () override |
| void | close () |
| QPdfDocument::Error | error () const |
| QPdfSelection | getAllText (int page ) |
| QPdfSelection | getSelection (int page , QPointF start , QPointF end ) |
| QPdfSelection | getSelectionAtIndex (int page , int startIndex , int maxLength ) |
| void | load (QIODevice * device ) |
| QPdfDocument::Error | load (const QString & fileName ) |
| QVariant | metaData (QPdfDocument::MetaDataField field ) const |
| int | pageCount () const |
(從 6.6 起)
int
|
pageIndexForLabel (const QString & label ) |
| QString | pageLabel (int page ) |
| QAbstractListModel * | pageModel () |
| QSizeF | pagePointSize (int page ) const |
| QString | password () const |
| QImage | render (int page , QSize imageSize , QPdfDocumentRenderOptions renderOptions = QPdfDocumentRenderOptions()) |
| void | setPassword (const QString & password ) |
| QPdfDocument::Status | status () const |
| void | pageCountChanged (int pageCount ) |
| void | pageModelChanged () |
| void | passwordChanged () |
| void | statusChanged (QPdfDocument::Status status ) |
This enum describes the error while attempting the last operation on the document.
| 常量 | 值 | 描述 |
|---|---|---|
QPdfDocument::Error::None
|
0
|
沒有齣現錯誤。 |
QPdfDocument::Error::Unknown
|
1
|
Unknown type of error. |
QPdfDocument::Error::DataNotYetAvailable
|
2
|
The document is still loading, it's too early to attempt the operation. |
QPdfDocument::Error::FileNotFound
|
3
|
The file given to load () was not found. |
QPdfDocument::Error::InvalidFileFormat
|
4
|
The file given to load () is not a valid PDF file. |
QPdfDocument::Error::IncorrectPassword
|
5
|
The password given to setPassword () is not correct for this file. |
QPdfDocument::Error::UnsupportedSecurityScheme
|
6
|
QPdfDocument is not able to unlock this kind of PDF file. |
另請參閱 QPdfDocument::error ().
此枚舉描述元數據的可用字段。
| 常量 | 值 | 描述 |
|---|---|---|
QPdfDocument::MetaDataField::Title
|
0
|
文檔的標題作為 QString . |
QPdfDocument::MetaDataField::Author
|
2
|
The name of the person who created the document as QString . |
QPdfDocument::MetaDataField::Subject
|
1
|
The subject of the document as QString . |
QPdfDocument::MetaDataField::Keywords
|
3
|
Keywords associated with the document as QString . |
QPdfDocument::MetaDataField::Creator
|
5
|
If the document was converted to PDF from another format, the name of the conforming product that created the original document from which it was converted as QString . |
QPdfDocument::MetaDataField::Producer
|
4
|
If the document was converted to PDF from another format, the name of the conforming product that converted it to PDF as QString . |
QPdfDocument::MetaDataField::CreationDate
|
6
|
The date and time the document was created as QDateTime . |
QPdfDocument::MetaDataField::ModificationDate
|
7
|
The date and time the document was most recently modified as QDateTime . |
另請參閱 QPdfDocument::metaData ().
Roles in pageModel ().
| 常量 | 值 | 描述 |
|---|---|---|
QPdfDocument::PageModelRole::Label
|
Qt::UserRole
|
The page number to be used for display purposes ( QString ). |
QPdfDocument::PageModelRole::PointSize
|
257
|
The page size in points (1/72 of an inch) ( QSizeF ). |
此枚舉描述文檔的當前狀態。
| 常量 | 值 | 描述 |
|---|---|---|
QPdfDocument::Status::Null
|
0
|
The initial status after the document has been created or after it has been closed. |
QPdfDocument::Status::Loading
|
1
|
The status after load () has been called and before the document is fully loaded. |
QPdfDocument::Status::Ready
|
2
|
The status when the document is fully loaded and its data can be accessed. |
QPdfDocument::Status::Unloading
|
3
|
The status after close () has been called on an open document. At this point the document is still valid and all its data can be accessed. |
QPdfDocument::Status::Error
|
4
|
加載後的狀態,若加載失敗。 |
另請參閱 QPdfDocument::status ().
[read-only]
pageCount
: const
int
This property holds the number of pages in the loaded document or
0
if no document is loaded.
訪問函數:
| int | pageCount () const |
通知程序信號:
| void | pageCountChanged (int pageCount ) |
[read-only]
pageModel
:
QAbstractListModel
* const
This property holds an instance of QAbstractListModel to provide page-specific metadata, containing one row for each page in the document.
訪問函數:
| QAbstractListModel * | pageModel () |
通知程序信號:
| void | pageModelChanged () |
另請參閱 QPdfDocument::PageModelRole .
This property holds the document password.
If the document is protected by a password, the user must provide it, and the application must set this property. Otherwise, it's not needed.
訪問函數:
| QString | password () const |
| void | setPassword (const QString & password ) |
通知程序信號:
| void | passwordChanged () |
[read-only]
status
: const
Status
This property holds the current status of the document.
訪問函數:
| QPdfDocument::Status | status () const |
通知程序信號:
| void | statusChanged (QPdfDocument::Status status ) |
[explicit]
QPdfDocument::
QPdfDocument
(
QObject
*
parent
)
構造新文檔采用父級對象 parent .
[override virtual noexcept]
QPdfDocument::
~QPdfDocument
()
銷毀文檔。
關閉文檔。
Returns the type of error if
status
is
Error
,或
NoError
if there is no error.
[invokable]
QPdfSelection
QPdfDocument::
getAllText
(
int
page
)
返迴所有文本及其邊界在給定 page .
注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .
[invokable]
QPdfSelection
QPdfDocument::
getSelection
(
int
page
,
QPointF
start
,
QPointF
end
)
Returns information about the text on the given page that can be found between the given start and end points, if any.
注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .
[invokable]
QPdfSelection
QPdfDocument::
getSelectionAtIndex
(
int
page
,
int
startIndex
,
int
maxLength
)
Returns information about the text on the given page that can be found beginning at the given startIndex with at most maxLength 字符。
注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .
Loads the document contents from device .
Loads the document contents from fileName .
Returns the meta data of the document for the given field .
[invokable, since 6.6]
int
QPdfDocument::
pageIndexForLabel
(const
QString
&
label
)
Returns the index of the page that has the
label
,或
-1
if not found.
注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .
該函數在 Qt 6.6 引入。
另請參閱 pageLabel ().
[invokable]
QString
QPdfDocument::
pageLabel
(
int
page
)
返迴 page number to be used for display purposes.
For example, a document may have multiple sections with different numbering. Perhaps the preface uses roman numerals, the body starts on page 1, and the appendix starts at A1. Whenever a PDF viewer shows a page number, to avoid confusing the user it should be the same "number" as is printed on the corner of the page, rather than the zero-based page index that we use in APIs (assuming the document author has made the page labels match the printed numbers).
If the document does not have custom page numbering, this function returns
page + 1
.
注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .
另請參閱 pageIndexForLabel ().
[invokable]
QSizeF
QPdfDocument::
pagePointSize
(
int
page
) const
Returns the size of page page in points (1/72 of an inch).
注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .
渲染 page 成 QImage 的大小 imageSize according to the provided renderOptions .
Returns the rendered page or an empty image in case of an error.
注意:若 imageSize does not match the aspect ratio of the page in the PDF document, the page is rendered scaled, so that it covers the complete imageSize .