QPdfDocument Class

QPdfDocument クラスは PDF ドキュメントを読み込み、そこからページをレンダリングします。詳細...

Header: #include <QPdfDocument>
Inherits: QObject

パブリックな型

enum class Error { None, Unknown, DataNotYetAvailable, FileNotFound, InvalidFileFormat, …, UnsupportedSecurityScheme }
enum class MetaDataField { Title, Author, Subject, Keywords, Creator, …, ModificationDate }
enum class PageModelRole { Label, PointSize }
enum class 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
(since 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)

詳細説明

メンバー型ドキュメント

enum class QPdfDocument::Error

この列挙型は、ドキュメントに対する最後の操作の際のエラーを記述します。

定数説明
QPdfDocument::Error::None0エラーは発生しませんでした。
QPdfDocument::Error::Unknown1エラーの種類が不明です。
QPdfDocument::Error::DataNotYetAvailable2ドキュメントはまだロード中であり、操作を試みるには時期尚早です。
QPdfDocument::Error::FileNotFound3load() に指定されたファイルが見つかりません。
QPdfDocument::Error::InvalidFileFormat4load() に指定されたファイルは有効な PDF ファイルではありません。
QPdfDocument::Error::IncorrectPassword5setPassword ()に指定されたパスワードが、このファイルに対して正しくありません。
QPdfDocument::Error::UnsupportedSecurityScheme6QPdfDocument この種類の PDF ファイルのロックを解除できません。

QPdfDocument::error()も参照してください

enum class QPdfDocument::MetaDataField

この列挙型は、利用可能なメタデータのフィールドを記述します。

定数説明
QPdfDocument::MetaDataField::Title0QString として、文書のタイトル。
QPdfDocument::MetaDataField::Author2QString として、文書を作成した人の名前。
QPdfDocument::MetaDataField::Subject1QString として、文書の件名。
QPdfDocument::MetaDataField::Keywords3QString と し て、 文書に関連す る キーワー ド 。
QPdfDocument::MetaDataField::Creator5その文書が別の形式か ら PDF へ変換 さ れた場合には、QString と し て、 その変換元文書を作成 し た準拠製品の名前。
QPdfDocument::MetaDataField::Producer4その文書が別の形式か ら PDF へ変換 さ れた場合には、 それを PDF へ変換 し た適合製品の名前をQString と し て示 し ます。
QPdfDocument::MetaDataField::CreationDate6文書が作成 さ れた日時をQDateTime と し て。
QPdfDocument::MetaDataField::ModificationDate7QDateTime と し て、 文書が最近更新 さ れた日時。

QPdfDocument::metaData ()も 参照 し て く だ さ い。

enum class QPdfDocument::PageModelRole

pageModel ()における役割。

定数説明
QPdfDocument::PageModelRole::LabelQt::UserRole表示用に使用するページ番号 (QString)。
QPdfDocument::PageModelRole::PointSize257ポイント単位のページ・サイズ (1/72 インチ) (QSizeF)。

enum class QPdfDocument::Status

この列挙型は、ドキュメントの現在のステータスを記述します。

定数説明
QPdfDocument::Status::Null0ドキュメントが作成された後、または閉じられた後の初期状態。
QPdfDocument::Status::Loading1load() が呼び出された後で、ドキュメントが完全に読み込まれる前の状態。
QPdfDocument::Status::Ready2文書が完全に読み込まれ、そのデータにアクセスできるようになったときの状態。
QPdfDocument::Status::Unloading3開いている文書に対してclose() がコールされた後の状態。この時点では、ドキュメントはまだ有効で、そのすべてのデータにアクセスできます。
QPdfDocument::Status::Error4読み込みに失敗した場合の、読み込み後のステータス。

QPdfDocument::status()も参照

プロパティ・ドキュメント

[read-only] pageCount : const int

このプロパティは、読み込まれたドキュメントのページ数を保持し、ドキュメントが読み込まれていない場合は0 を保持します。

アクセス関数:

int pageCount() const

通知シグナル:

void pageCountChanged(int pageCount)

[read-only] pageModel : QAbstractListModel* const

このプロパティは、ページ固有のメタデータを提供するためにQAbstractListModel のインスタンスを保持し、ドキュメントの各ページに対して1行を含みます。

アクセス関数:

QAbstractListModel *pageModel()

ノーティファイアシグナル:

void pageModelChanged()

QPdfDocument::PageModelRoleも参照

password : QString

このプロパティは文書のパスワードを保持する。

ドキュメントがパスワードで保護されている場合、ユーザはそれを提供しなければならず、アプリケーションはこのプロパティを設定しなければならない。そうでなければ、このプロパティは必要ありません。

アクセス関数:

QString password() const
void setPassword(const QString &password)

通知シグナル:

void passwordChanged()

[read-only] status : const Status

このプロパティは、ドキュメントの現在の状態を保持する。

アクセス関数:

QPdfDocument::Status status() const

Notifier シグナル:

void statusChanged(QPdfDocument::Status status)

メンバ関数ドキュメント

[explicit] QPdfDocument::QPdfDocument(QObject *parent)

親オブジェクトparent を持つ新しいドキュメントを作成します。

[override virtual noexcept] QPdfDocument::~QPdfDocument()

文書を破棄する。

void QPdfDocument::close()

文書を閉じる。

QPdfDocument::Error QPdfDocument::error() const

statusError の場合はエラーの種類を、エラーがない場合はNoError を返す。

[invokable] QPdfSelection QPdfDocument::getAllText(int page)

与えられたpage 上のすべてのテキストとその境界を返す。

注意: この関数はメタオブジェクトシステムやQMLから呼び出すことができます。Q_INVOKABLE を参照してください。

[invokable] QPdfSelection QPdfDocument::getSelection(int page, QPointF start, QPointF end)

与えられたstartend の間にある、与えられたpage のテキストに関する情報を返します。

注意: この関数はメタオブジェクトシステムやQMLから呼び出すことができます。Q_INVOKABLE を参照してください。

[invokable] QPdfSelection QPdfDocument::getSelectionAtIndex(int page, int startIndex, int maxLength)

与えられたpage 上のテキストのうち、与えられたstartIndex から始まる、最大maxLength 文字のテキストに関する情報を返します。

注意: この関数はメタオブジェクトシステムやQMLから呼び出すことができます。Q_INVOKABLE を参照してください。

void QPdfDocument::load(QIODevice *device)

device から文書の内容を読み込みます。

QPdfDocument::Error QPdfDocument::load(const QString &fileName)

fileName から文書の内容を読み込みます。

QVariant QPdfDocument::metaData(QPdfDocument::MetaDataField field) const

与えられたfield のドキュメントのメタデータを返します。

[invokable, since 6.6] int QPdfDocument::pageIndexForLabel(const QString &label)

label を持つページのインデックスを返し、見つからない場合は-1 を返す。

注意: この関数はメタオブジェクトシステムやQMLから呼び出すことができます。Q_INVOKABLE を参照してください。

この関数は Qt 6.6 で導入されました。

pageLabel()も参照してください

[invokable] QString QPdfDocument::pageLabel(int page)

表示用に使用するpage 番号を返す。

例えば、文書には複数のセクションがあり、それぞれ異なる番号が振られている場合があります。た と えば序文はローマ数字で、本文は 1 ページ目から、付録は A1 から始まるかもしれません。PDFビューアがページ番号を表示するときはいつでも、ユーザーを混乱させないために、APIで使っているゼロベースのページインデックスではなく、ページの隅に印刷されているのと同じ「番号」であるべきです(文書作成者がページラベルを印刷された番号と一致させていると仮定して)。

文書にカスタムページ番号がない場合、この関数はpage + 1 を返します。

注意: この関数はメタオブジェクトシステムやQMLから呼び出すことができます。Q_INVOKABLE を参照してください。

pageIndexForLabel()も参照してください

[invokable] QSizeF QPdfDocument::pagePointSize(int page) const

ページpage のサイズをポイント(1/72インチ)で返します。

注意: この関数はメタオブジェクトシステムやQMLから呼び出すことができます。Q_INVOKABLE を参照してください。

QImage QPdfDocument::render(int page, QSize imageSize, QPdfDocumentRenderOptions renderOptions = QPdfDocumentRenderOptions())

提供されたrenderOptions に従って、page をサイズimageSizeQImage にレンダリングします。

レンダリングされたページを返すか、エラーの場合は空の画像を返します。

注 :imageSize が PDF 文書内のページの縦横比 と 一致 し ていない と き は、 ページは拡大縮小 さ れてレ ン ダ リ さ れ、imageSize 全体を覆 う よ う にな り ます。

© 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.