Page (ページ)#
ドキュメントページを表すクラス。ページオブジェクトは:meth:Document.load_page
またはドキュメントをインデックスで参照することで作成されます(例:doc[n]
) - 独立したコンストラクタはありません。
ドキュメントとそのページとの親子関係があります。ドキュメントが閉じられるか削除されると、存在するすべてのページオブジェクト(およびそれに関連する子供たちも)が使用できなくなります(「孤児」になります)。ページのプロパティまたはメソッドを使用している場合、例外が発生します。
便宜のために、いくつかのページメソッドには Document (ドキュメント) の対応するメソッドがあります。この章の最後に概要があります。
注釈
Many times in this chapter we are using the term coordinate. It is of high importance to have at least a basic understanding of what that is and that you feel comfortable with the section Coordinates.
ページの修正#
ページのプロパティを変更し、ページの内容を追加または変更することは、PDFドキュメントのみで使用可能です。
要するに、PyMuPDFでできることは次のとおりです:
ページの回転とページの可視部分(「クロップボックス」)の変更。
画像、他のPDFページ、テキスト、単純な幾何学的オブジェクトの挿入。
アノテーションとフォームフィールドの追加。
注釈
Methods require coordinates (points, rectangles) to put content in desired places. Please be aware that these coordinates must always be provided relative to the unrotated page (since v1.17.0). The reverse is also true: except Page.rect
, resp. Page.bound()
(both reflect when the page is rotated), all coordinates returned by methods and attributes pertain to the unrotated page.
したがって、Page.get_image_bbox()
などのメソッドの返される値は、Page.set_rotation()を実行しても変更されません。同じことが Page.get_text()
、アノテーションの矩形などから返される座標にも当てはまります。オブジェクトが 回転した座標 でどこにあるかを調べたい場合は、座標を:attr:Page.rotation_matrix
で乗算します。Page.derotation_matrix
とその逆行列もあり、他のリーダーと連携する際に使用できます。この点で異なる動作をするかもしれません。
注釈
ページに注釈、リンク、またはフォームフィールドを追加または更新し、直後にこれらの新しいまたは更新されたアイテムを操作する必要がある場合(つまり ページを離れずに)、Document.reload_page()
を使用してページを再読み込みする必要があります。
一般的にはページを再読み込みすることをお勧めしますが、すべてのケースで厳密に必要とされるわけではありません。ただし、PyMuPDFの注釈とウィジェットの種類の一部は、MuPDFと比較して拡張機能を持っています。今後もこれらの拡張機能が増えるかもしれません
ページを再読み込むことで、変更がPDF構造に完全に適用され、Pixa画像を作成したり、アノテーション、リンク、フォームフィールドを正常にイテレートしたりできるようになります。
メソッド / 属性 |
短い説明 |
---|---|
PDFのみ:キャレットアノテーションを追加します |
|
PDFのみ:円注釈を追加します |
|
PDFのみ:ファイル添付アノテーションを追加します |
|
PDFのみ:テキストアノテーションを追加します |
|
PDFのみ:「ハイライト」アノテーションを追加します |
|
PDFのみ:インク注釈を追加します |
|
PDFのみ:線アノテーションを追加します |
|
PDFのみ:多角形アノテーションを追加します |
|
PDFのみ:多線アノテーションを追加します |
|
PDFのみ:四角アノテーション釈を追加します |
|
PDFのみ:黒塗りアノテーションを追加します |
|
PDFのみ:「波線」アノテーションを追加します |
|
PDFのみ:「スタンプ」アノテーションを追加します |
|
PDFのみ:「取り消し線」アノテーションを追加します |
|
PDFのみ:コメントを追加します |
|
PDFのみ:「下線」アノテーションを追加します |
|
PDFのみ:PDFフォームフィールドを追加します |
|
PDFのみ:アノテーション(およびウィジェット)の名前のリスト |
|
PDFのみ:アノテーション(およびウィジェット)のxrefのリスト |
|
ページ上のアノテーションのジェネレーターを返します |
|
PDFのみ:ページの塗りつぶしを処理します |
|
ページの矩形 |
|
PDF only: bounding boxes of vector graphics |
|
PDFのみ:アノテーションを削除します |
|
PDFのみ:画像を削除します |
|
PDFのみ:リンクを削除します |
|
PDFのみ:ウィジェット/フィールドを削除します |
|
PDFのみ:三次ベジエ曲線を描画します |
|
PDFのみ:円を描画します |
|
PDFのみ:特別なベジエ曲線を描画します |
|
PDFのみ:直線を描画します |
|
PDFのみ:楕円を描画します |
|
PDFのみ:点のシーケンスを接続します |
|
PDF のみ: クアッドを描く |
|
PDFのみ:四角形を描画します |
|
PDFのみ:円セクタを描画します |
|
PDFのみ:波線を描画します |
|
PDFのみ:ジグザグ線を描画します |
|
ページ上のテーブルを検出します |
|
ページ上のベクトルグラフィックを取得します |
|
PDFのみ:参照されたフォントのリストを取得 |
|
PDFのみ:埋め込まれた画像のバウンディングボックスと行列を取得 |
|
使用されるすべての画像のメタ情報のリストを取得 |
|
PDFのみ: |
|
PDFのみ:参照された画像のリストを取得 |
|
PDFのみ:ページのラベルを返す |
|
すべてのリンクを取得 |
|
ラスターフォーマットのページイメージを作成 |
|
SVGフォーマットのページイメージを作成 |
|
ページのテキストを抽出 |
|
特定の矩形に含まれるテキストを抽出 |
|
ページのOCR付きのTextPageを作成 |
|
ページのTextPageを作成 |
|
PDFのみ:参照されたxobjectのリストを取得 |
|
PDFのみ:ページで使用するフォントを挿入 |
|
PDFのみ:画像を挿入 |
|
PDFのみ:リンクを挿入 |
|
PDFのみ:テキストを挿入 |
|
PDF only: insert html text in a rectangle |
|
PDFのみ:テキストボックスを挿入 |
|
ページ上のリンクのジェネレータを返す |
|
PDFのみ:特定のアノテーションを読み込む |
|
PDFのみ:特定のフィールドを読み込む |
|
ページ上の最初のリンクを返す |
|
PDFのみ:新しい Shape(シェイプ) を作成 |
|
PDF only: set page rotation to 0 |
|
PDFのみ:画像を置換 |
|
文字列を検索 |
|
PDFのみ: |
|
PDFのみ:/BleedBoxを変更 |
|
PDFのみ: |
|
PDFのみ:/MediaBoxを変更 |
|
PDFのみ:ページの回転を設定 |
|
PDFのみ: |
|
PDFのみ:PDFページ画像を表示 |
|
PDFのみ:リンクを変更 |
|
ページ上のフィールドのジェネレータを返す |
|
1つ以上の TextWriter (テキストライター) オブジェクトを書き込む |
|
|
|
ページの |
|
ページの |
|
ページの |
|
ページの |
|
PDFのみ:回転されていないページ空間内の座標を取得 |
|
ページ上の最初の Annot (注釈) |
|
ページ上の最初の Link (リンク) |
|
ページ上の最初のウィジェット(フォームフィールド) |
|
|
|
ページの |
|
ページ番号 |
|
所属するドキュメントオブジェクト |
|
ページの矩形 |
|
PDFのみ:回転したページ空間内の座標を取得 |
|
PDFのみ:ページの回転 |
|
PDFのみ:PDFとMuPDFのスペース間を変換 |
|
PDFのみ:ページの |
クラス API
- class Page#
- bound()#
Determine the rectangle of the page. Same as property
Page.rect
. For PDF documents this usually also coincides withmediabox
andcropbox
, but not always. For example, if the page is rotated, then this is reflected by this method -- thePage.cropbox
however will not change.- 戻り値の型:
- add_caret_annot(point)#
PDFのみ: ケアットアイコンを追加します。ケアットアノテーションは通常、ページ上でテキストの編集が存在することを示すために使用される視覚的なシンボルです
- パラメータ:
point (point_like) -- point (point_like) – MuPDFが提供するアイコンを含む20 x 20の長方形の左上のポイント。
- 戻り値の型:
- 戻り値:
作成されたアノテーション。ストロークの色は青=(0, 0, 1)で、塗りつぶしの色はサポートされていません。
Show/hide history
v1.16.0で新たに追加された
- add_text_annot(point, text, icon='Note')#
PDFのみ: コメントアイコン(「付箋」)を追加し、それに関連するテキストを含めます。アイコンのみが表示され、関連するテキストは非表示で、多くのPDFビューアではアイコンの上にマウスを重ねることで可視化できます。
- パラメータ:
point (point_like) -- 提供されたMuPDFアイコンが含まれる20 x 20の矩形の左上の点。
text (str) -- コメントテキスト。これはダブルクリックまたはアイコンの上にカーソルを合わせることで表示されます。ラテン文字を含むことができます。
icon (str) -- choose one of "Note" (default), "Comment", "Help", "Insert", "Key", "NewParagraph", "Paragraph" as the visual symbol for the embodied text [4]. (New in v1.16.0)
- 戻り値の型:
- 戻り値:
作成された注釈。ストロークカラーは黄色(1, 1, 0)、塗りつぶしカラーのサポートはありません。
- add_freetext_annot(rect, text, fontsize=12, fontname='helv', border_color=None, text_color=0, fill_color=1, rotate=0, align=TEXT_ALIGN_LEFT)#
PDFのみ: 指定された矩形にテキストを追加します。
- パラメータ:
rect (rect_like) -- テキストを挿入する矩形。テキストはボックスの幅で自動的に改行されます。ボックスに収まらない行は見えません。
text (str) -- the text. May contain any mixture of Latin, Greek, Cyrillic, Chinese, Japanese and Korean characters. The respective required font is automatically determined. (New in v1.17.0)
fontsize (float) --
fontsize
。デフォルトは12です。fontname (str) -- the font name. Default is "Helv". Accepted alternatives are "Cour", "TiRo", "ZaDb" and "Symb". The name may be abbreviated to the first two characters, like "Co" for "Cour". Lower case is also accepted. Bold or italic variants of the fonts are not accepted (changed in v1.16.0). A user-contributed script provides a circumvention for this restriction -- see section Using Buttons and JavaScript in chapter FAQ. The actual font to use is now determined on a by-character level, and all required fonts (or sub-fonts) are automatically included. Therefore, you should rarely ever need to care about this parameter and let it default (except you insist on a serifed font for your non-CJK text parts). (New in v1.17.0)
text_color (sequence,float) -- the text color. Default is black. (New in v1.16.0)
fill_color (sequence,float) -- the fill color. Default is white. (New in v1.16.0)
text_color -- テキストの色。デフォルトは黒です。
border_color (sequence,float) -- the border color. Default is
None
. (New in v1.19.6)align (int) -- text alignment, one of TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT - justify is not supported. (New in v1.17.0)
rotate (int) -- テキストの向き。受け入れられる値は0、90、270で、無効なエントリはゼロに設定されます。
- 戻り値の型:
- 戻り値:
作成された注釈。色のプロパティは、
Annot.update()
の特別なパラメータを使用して のみ変更できます。そこでは、テキストの色とは異なる境界色を設定することもできます。
Show/hide history
v1.19.6で変更:境界色パラメータを追加
- add_file_annot(pos, buffer, filename, ufilename=None, desc=None, icon='PushPin')#
PDFのみ: 指定された場所に「PushPin」アイコンを持つファイル添付注釈を追加します。
- パラメータ:
pos (point_like) -- ムPDFで提供される「PushPin」アイコンを含む18x18の四角形の左上のポイント。
buffer (bytes,bytearray,BytesIO) --
格納するデータ(実際のファイルコンテンツ、任意のデータなど)。
Changed in v1.14.13: io.BytesIO is now also supported.
filename (str) -- データに関連付けるファイル名。
ufilename (str) -- ファイルのPDF Unicodeバージョンのオプション。デフォルトはファイル名です。
desc (str) -- ファイルのオプションの説明。デフォルトはファイル名です。
icon (str) -- choose one of "PushPin" (default), "Graph", "Paperclip", "Tag" as the visual symbol for the attached data [4]. (New in v1.16.0)
- 戻り値の型:
- 戻り値:
作成された注釈。線の色は黄色(1, 1, 0)、塗りつぶしのサポートはありません。
- add_ink_annot(list)#
PDFのみ: "freehand"の落書き注釈を追加します。
- パラメータ:
list (sequence) -- 1つまたは複数のリストからなり、それぞれが
point_like
アイテムを含むリストの1つです。これらのサブリスト内の各アイテムは、接続された線が描画される Point (ポイント) として解釈されます。したがって、個々のサブリストは別々の描画ラインを表します。- 戻り値の型:
- 戻り値:
作成された注釈はデフォルトの外観で黒色(0, 0, 0)で、線の幅は1です。塗りつぶしのサポートはありません。
- add_line_annot(p1, p2)#
PDFのみ: 直線注釈を追加します。
- パラメータ:
p1 (point_like) -- 直線の開始点。
p2 (point_like) -- 直線の終点。
- 戻り値の型:
- 戻り値:
作成された注釈。線(ストローク)の色は赤色(1, 0, 0)で、線の幅は1です。塗りつぶしのサポートはありません。アノテーションの四角形 は、各点を囲む半径 3 * 線幅の円で作成され、各点の周りにシンボルの線の終わりのためのスペースを確保します。
- add_rect_annot(rect)#
- add_circle_annot(rect)#
PDFのみ: 長方形、または円の注釈を追加します。
- パラメータ:
rect (rect_like) -- 円または長方形が描かれる矩形。有限で空でない必要があります。矩形が正方形でない場合、楕円が描画されます。
- 戻り値の型:
- 戻り値:
作成された注釈。線(ストローク)の色は赤色(1、0、0)、線の幅は1で、塗りつぶしのサポートがあります
Redactions#
- add_redact_annot(quad, text=None, fontname=None, fontsize=11, align=TEXT_ALIGN_LEFT, fill=(1, 1, 1), text_color=(0, 0, 0), cross_out=True)#
PDF only: Add a redaction annotation. A redaction annotation identifies content to be removed from the document. Adding such an annotation is the first of two steps. It makes visible what will be removed in the subsequent step,
Page.apply_redactions()
.- パラメータ:
quad (quad_like,rect_like) -- 常に注釈の矩形と等しい削除する領域を指定します。これはrect_likeまたはquad_likeオブジェクトである必要があります。四角形が指定された場合、包括的な矩形が取られます。
text (str) -- text to be placed in the rectangle after applying the redaction (and thus removing old content). (New in v1.16.12)
fontname (str) --
the font to use when text is given, otherwise ignored. The same rules apply as for
Page.insert_textbox()
-- which is the methodPage.apply_redactions()
internally invokes. The replacement text will be vertically centered, if this is one of the CJK or PDFベース14フォント. (New in v1.16.12)注釈
ページの 既存 のフォントの場合、参照名を fontname として使用してください(これは
Page.get_fonts()
のエントリの item[4] です)。新しいビルトインでない フォントの場合、次の手順を実行します:
page.insert_text(point, # anywhere, but outside all redaction rectangles "something", # some non-empty string fontname="newname", # new, unused reference name fontfile="...", # desired font file render_mode=3, # makes the text invisible ) page.add_redact_annot(..., fontname="newname")
fontsize (float) -- the
fontsize
to use for the replacing text. If the text is too large to fit, several insertion attempts will be made, gradually reducing thefontsize
to no less than 4. If then the text will still not fit, no text insertion will take place at all. (New in v1.16.12)align (int) -- the horizontal alignment for the replacing text. See
insert_textbox()
for available values. The vertical alignment is (approximately) centered if a PDF built-in font is used (CJK or PDFベース14フォント). (New in v1.16.12)fill (sequence) -- the fill color of the rectangle after applying the redaction. The default is white = (1, 1, 1), which is also taken if None is specified. To suppress a fill color altogether, specify False. In this cases the rectangle remains transparent. (New in v1.16.12)
text_color (sequence) -- the color of the replacing text. Default is black = (0, 0, 0). (New in v1.16.12)
cross_out (bool) -- add two diagonal lines to the annotation rectangle. (New in v1.17.2)
- 戻り値の型:
- 戻り値:
the created annotation. Its standard appearance looks like a red rectangle (no fill color), optionally showing two diagonal lines. Colors, line width, dashing, opacity and blend mode can now be set and applied via
Annot.update()
like with other annotations. (Changed in v1.17.2)
Show/hide history
新機能 v1.16.11
- apply_redactions(images=PDF_REDACT_IMAGE_PIXELS | 2, graphics=PDF_REDACT_LINE_ART_IF_TOUCHED | 2, text=PDF_REDACT_TEXT_REMOVE | 0)#
PDF only: Remove all content contained in any redaction rectangle on the page.
このメソッドは、ページからすべての赤塗りを適用して削除します。
- パラメータ:
images (int) -- How to redact overlapping images. The default (2) blanks out overlapping pixels.
PDF_REDACT_IMAGE_NONE | 0
ignores, andPDF_REDACT_IMAGE_REMOVE | 1
completely removes images overlapping any redaction annotation. OptionPDF_REDACT_IMAGE_REMOVE_UNLESS_INVISIBLE | 3
only removes images that are actually visible.graphics (int) -- How to redact overlapping vector graphics (also called "line-art" or "drawings"). The default (2) removes any overlapping vector graphics.
PDF_REDACT_LINE_ART_NONE | 0
ignores, andPDF_REDACT_LINE_ART_IF_COVERED | 1
removes graphics fully contained in a redaction annotation. When removing line-art, please be aware that stroked vector graphics (i.e. type "s" or "sf") have a larger wrapping rectangle than one might expect: first of all, at least 50% of the path's line width have to be added in each direction to truly include all of the drawing. If a so-called "miter limit" is provided (see page 121 of the PDF specification), the enlarging value ismiter * width / 2
. So, when letting everything default (width = 1, miter = 10), the redaction rectangle should be at least 5 points larger in every direction.text (int) -- Whether to redact overlapping text. The default
PDF_REDACT_TEXT_REMOVE | 0
removes all characters whose boundary box overlaps any redaction rectangle. This complies with the original legal / data protection intentions of redaction annotations. Other use cases however may require to keep text while redacting vector graphics or images. This can be achieved by settingtext=True|PDF_REDACT_TEXT_NONE | 1
. This does not comply with the data protection intentions of redaction annotations. Do so at your own risk.
- 戻り値:
True
if at least one redaction annotation has been processed,False
otherwise.
注釈
赤塗りの四角に含まれるテキストは、物理的に ページから削除されます(適切なゴミオプションを使用したDocument.save()の場合)、テキスト抽出などの場所にはもはや表示されません。また、すべての赤塗りの注釈も削除されます。他の注釈には影響しません。
重なっているすべてのリンクは削除されます。リンクの四角がテキストを覆っている場合、テキストの重なる部分のみが削除されます。画像もリンクの四角によってカバーされている場合、同様のことが適用されます。
The overlapping parts of images will be blanked-out for default option
PDF_REDACT_IMAGE_PIXELS
(changed in v1.18.0). Option 0 does not touch any images and 1 will remove any image with an overlap.images=PDF_REDACT_IMAGE_REMOVE
のオプションの場合、このページの 画像への参照 のみが削除されます。適切なゴミ収集オプションがあると、画像はファイルから完全に削除されます。images=PDF_REDACT_IMAGE_PIXELS
のオプションでは、新しいPNG形式の画像が作成され、ページは元の画像の代わりにそれを使用します。このプロセスの一環として、元の画像は削除されず、他のページでは引き続き元の画像が表示される可能性があります。さらに、新しい変更されたPNG画像は現在 圧縮されていない状態で保存されています 。保存時に適切なゴミ収集メソッドと圧縮オプションを選択する際に、これらの側面を考慮してください。Text removal is done by character: A character is removed if its bbox has a non-empty overlap with a redaction rectangle (changed in MuPDF v1.17). Depending on the font properties and / or the chosen line height, deletion may occur for undesired text parts. Using
Tools.set_small_glyph_heights()
with a True argument before text search may help to prevent this.赤塗りは、PDF内の単語を置き換えるための簡単な方法であり、単語を物理的に削除するためのものです。テキスト抽出または検索方法を使用して単語「秘密」を見つけ、それぞれの出現ごとに代替テキスト「xxxxxx」を使用して赤塗りを挿入します。
注意が必要です。代替テキストが元のテキストよりも長い場合、見栄えが悪くなったり、改行が発生したり、新しいテキストがまったく表示されなくなる可能性があるためです。
いくつかの理由から、新しいテキストは古いテキストとまったく同じ行に配置されないことがあります。特に、代替フォントがCJKまたはPDF PDFベース14フォント の場合には特に当てはまります。
Show/hide history
新機能 v1.16.11
v1.16.12で変更:以前の mark パラメータは削除されました。代わりに、各赤字注釈の個々の塗りつぶし色で各赤字領域が塗りつぶされます。アノテーションで text が指定された場合、そのテキストを挿入するために、redactionで提供されたパラメータを使用して
insert_textbox()
が呼び出されます。v1.18.0で変更:赤字領域と重なる画像を処理するためのオプションが追加されました。
Changed in v1.23.27: added option for removing graphics as well.
Changed in v1.24.2: added option
keep_text
to leave text untouched.
- add_polyline_annot(points)#
- add_polygon_annot(points)#
PDFのみ:指定されたポイントを接続する線から成る注釈を追加します。多角形 (Polygon) の最初と最後のポイントは自動的に接続されますが、PolyLine ではそれが発生しません。各ポイントは半径3の円で囲まれた最小の 四角形 として自動的に作成されます(半径3 = 3 * 線の幅)。以下は、色や線端を変更した「PolyLine」の例を示しています。
- パラメータ:
points (list) -- points(list)–
point_like
オブジェクトのリスト。- 戻り値の型:
- 戻り値:
作成されたアノテーションです。線の色は黒で描画され、線の幅は1で、塗りつぶし色はサポートされています。このような外見を実現するために、Annot (注釈) のメソッドを使用して変更を加えることができます。
- add_underline_annot(quads=None, start=None, stop=None, clip=None)#
- add_strikeout_annot(quads=None, start=None, stop=None, clip=None)#
- add_squiggly_annot(quads=None, start=None, stop=None, clip=None)#
- add_highlight_annot(quads=None, start=None, stop=None, clip=None)#
PDFのみ: これらのアノテーションは通常、以前に何らかの方法で見つかったテキスト(たとえば、
Page.search_for()
を使用して)をマーキングするために使用されます。ただし、これは必須ではありません:何でも「マーク」することができます。通常、アノテーションの種類ごとに標準の(ストロークのみで、塗りつぶし色はサポートされていません)色が選択されます。ハイライト用に 黄色、取り消し線用に 赤色、下線用に 緑色、波線下線用に マゼンタ色 です。
これらの四つのメソッドは、引数を Quad (クアッド) オブジェクトのリストに変換します。その後、アノテーション の矩形は、これらの四角形を包含するように計算されます。
注釈
search_for()
は Rect (矩形) または:ref:Quad (クアッド) オブジェクトのリストを返します。このようなリストは、これらのアノテーションタイプの引数として直接使用でき、検索文字列のすべての出現に対して 共通のアノテーション を提供します:>>> # prefer quads=True in text searching for annotations! >>> quads = page.search_for("pymupdf", quads=True) >>> page.add_highlight_annot(quads)
注釈
明らかに、テキストマーカーアノテーションは、マークされる領域の上部、下部、左部、右部が何であるかを知る必要があります。引数がquadsの場合、この情報は四角形のポイントのシーケンスによって提供されます。対照的に、矩形ははるかに少ない情報を提供します - これは、四角形の四つの角を使用して24の異なる四角形が構築できるという事実によって示されています。
したがって、正しいアノテーションを確保するために、テキスト検索に
quads
オプションを使用することを 強くお勧めします。同様の考慮事項は、Page.get_text()
の「dict」/「rawdict」オプションで抽出された テキストスパン をマークする場合にも適用されます。この場合の四角形の計算方法の詳細については、FAQ の「非水平テキストのマーキング方法」セクションを参照してください。- パラメータ:
quads (rect_like,quad_like,list,tuple) -- the location(s) -- rectangle(s) or quad(s) -- to be marked. (Changed in v1.14.20) A list or tuple must consist of
rect_like
orquad_like
items (or even a mixture of either). Every item must be finite, convex and not empty (as applicable). Set this parameter to None if you want to use the following arguments (Changed in v1.16.14). And vice versa: if not None, the remaining parameters must be None.start (point_like) -- start text marking at this point. Defaults to the top-left point of clip. Must be provided if
quads
is None. (New in v1.16.14)stop (point_like) -- stop text marking at this point. Defaults to the bottom-right point of clip. Must be used if
quads
is None. (New in v1.16.14)clip (rect_like) -- only consider text lines intersecting this area. Defaults to the page rectangle. Only use if
start
andstop
are provided. (New in v1.16.14)
- 戻り値の型:
Annot (注釈) or None (changed in v1.16.14).
- 戻り値:
the created annotation. If quads is an empty list, no annotation is created (changed in v1.16.14).
注釈
You can use parameters start, stop and clip to highlight consecutive lines between the points start and stop (starting with v1.16.14). Make use of clip to further reduce the selected line bboxes and thus deal with e.g. multi-column pages. The following multi-line highlight on a page with three text columns was created by specifying the two red points and setting clip accordingly.
- cluster_drawings(clip=None, drawings=None, x_tolerance=3, y_tolerance=3)#
Cluster vector graphics (synonyms are line-art or drawings) based on their geometrical vicinity. The method walks through the output of
Page.get_drawings()
and joins paths whosepath["rect"]
are closer to each other than some tolerance values (given in the arguments). The result is a list of rectangles that each wrap things like tables (with gridlines), pie charts, bar charts, etc.- パラメータ:
clip (rect_like) -- only consider paths inside this area. The default is the full page.
drawings (list) -- (optional) provide a previously generated output of
Page.get_drawings()
. IfNone
the method will execute the method.x_tolerance (float) --
- find_tables(clip=None, strategy=None, vertical_strategy=None, horizontal_strategy=None, vertical_lines=None, horizontal_lines=None, snap_tolerance=None, snap_x_tolerance=None, snap_y_tolerance=None, join_tolerance=None, join_x_tolerance=None, join_y_tolerance=None, edge_min_length=3, min_words_vertical=3, min_words_horizontal=1, intersection_tolerance=None, intersection_x_tolerance=None, intersection_y_tolerance=None, text_tolerance=None, text_x_tolerance=None, text_y_tolerance=None, add_lines=None)#
Find tables on the page and return an object with related information. Typically, the default values of the many parameters will be sufficient. Adjustments should ever only be needed in corner case situations.
- パラメータ:
clip (rect_like) -- specify a region to consider within the page rectangle and ignore the rest. Default is the full page.
strategy (str) --
Request a table detection strategy. Valid values are "lines", "lines_strict" and "text".
Default is "lines" which uses all vector graphics on the page to detect grid lines.
Strategy "lines_strict" ignores borderless rectangle vector graphics. Sometimes single text pieces have background colors which may lead to false columns or lines. This strategy ignores them and can thus increase detection precision.
If "text" is specified, text positions are used to generate "virtual" column and / or row boundaries. Use
min_words_*
to request the number of words for considering their coordinates.Use parameters
vertical_strategy
andhorizontal_strategy
instead for a more fine-grained treatment of the dimensions.horizontal_lines (sequence[floats]) -- y-coordinates of rows. If provided, there will be no attempt to identify additional table rows. This influences table detection.
vertical_lines (sequence[floats]) -- x-coordinates of columns. If provided, there will be no attempt to identify additional table columns. This influences table detection.
min_words_vertical (int) -- relevant for vertical strategy option "text": at least this many words must coincide to establish a virtual column boundary.
min_words_horizontal (int) -- relevant for horizontal strategy option "text": at least this many words must coincide to establish a virtual row boundary.
snap_tolerance (float) -- Any two horizontal lines whose y-values differ by no more than this value will be snapped into one. Accordingly for vertical lines. Default is 3. Separate values can be specified instead for the dimensions, using
snap_x_tolerance
andsnap_y_tolerance
.join_tolerance (float) -- Any two lines will be joined to one if the end and the start points differ by no more than this value (in points). Default is 3. Instead of this value, separate values can be specified for the dimensions using
join_x_tolerance
andjoin_y_tolerance
.edge_min_length (float) -- Ignore a line if its length does not exceed this value (points). Default is 3.
intersection_tolerance (float) -- When combining lines into cell borders, orthogonal lines must be within this value (points) to be considered intersecting. Default is 3. Instead of this value, separate values can be specified for the dimensions using
intersection_x_tolerance
andintersection_y_tolerance
.text_tolerance (float) -- Characters will be combined into words only if their distance is no larger than this value (points). Default is 3. Instead of this value, separate values can be specified for the dimensions using
text_x_tolerance
andtext_y_tolerance
.add_lines (tuple,list) -- Specify a list of "lines" (i.e. pairs of
point_like
objects) as additional, "virtual" vector graphics. These lines may help with table and / or cell detection and will not otherwise influence the detection strategy. Especially, in contrast to parametershorizontal_lines
andvertical_lines
, they will not prevent detecting rows or columns in other ways. These lines will be treated exactly like "real" vector graphics in terms of joining, snapping, intersectiing, minimum length and containment in theclip
rectangle. Similarly, lines not parallel to any of the coordinate axes will be ignored.
- 戻り値:
TableFinder
オブジェクトには、次の重要な属性があります:cells
: a list of all bboxes on the page, that have been identified as table cells (across all tables). Each cell is arect_like
tuple(x0, y0, x1, y1)
of coordinates orNone
.tables
: a list ofTable
objects. This is[]
if the page has no tables. Single tables can be found as items of this list. But theTableFinder
object itself is also a sequence of its tables. This means that iftabs
is aTableFinder
object, then table "n" is delivered bytabs.tables[n]
as well as by the shortertabs[n]
.Table
オブジェクトには次の属性があります:bbox
: the bounding box of the table as a tuple(x0, y0, x1, y1)
.cells
: bounding boxes of the table's cells (list of tuples). A cell may also beNone
.extract()
: this method returns the text content of each table cell as a list of list of strings.to_markdown()
: this method returns the table as a string in markdown format (compatible to Github). Supporting viewers can render the string as a table. This output is optimized for small token sizes, which is especially beneficial for LLM/RAG feeds. Pandas DataFrames (see methodto_pandas()
below) offer an equivalent markdown table output which however is better readable for the human eye.to_pandas()
: this method returns the table as a pandas DataFrame. DataFrames are very versatile objects allowing a plethora of table manipulation methods and outputs to almost 20 well-known formats, among them Excel files, CSV, JSON, markdown-formatted tables and more.DataFrame.to_markdown()
generates a Github-compatible markdown format optimized for human readability. This method however requires the package [tablutate](https://pypi.org/project/tabulate/) to installed in addition to pandas itself.header
: aTableHeader
object containing header information of the table.col_count
: an integer containing the number of table columns.row_count
: an integer containing the number of table rows.rows
: a list ofTableRow
objects containing two attributes,bbox
is the boundary box of the row, andcells
is a list of table cells contained in this row.
TableHeader
オブジェクトには次の属性があります:bbox
: the bounding box of the header.cells
: a list of bounding boxes containing the name of the respective column.names
: a list of strings containing the text of each of the cell bboxes. They represent the column names -- which are used when exporting the table to pandas DataFrames, markdown, etc.external
: a bool indicating whether the header bbox is outside the table body (True
) or not. Table headers are never identified by theTableFinder
logic. Therefore, ifexternal
is true, then the header cells are not part of any cell identified byTableFinder
. Ifexternal == False
, then the first table row is the header.
これらの Jupyter notebooks をご覧ください。これらのノートブックでは、1つのページに複数のテーブルがある場合や、複数のページにまたがるテーブル断片を結合するなど、標準的な状況がカバーされています。
Show/hide history
新機能バージョン1.23.0
Changed in version 1.23.19: new argument
add_lines
.
重要
There is also the pdf2docx extract tables method which is capable of table extraction if you prefer.
- add_stamp_annot(rect, stamp=0)#
PDF専用: "ドラフト"、"機密"などの文書の意図した使用を示すための「スタンプ」のような注釈を追加します。
- パラメータ:
rect (rect_like) -- アノテーションを配置する矩形領域。
stamp (int) -- スタンプテキストのID番号。使用可能なスタンプについては スタンプ注釈アイコン を参照してください。
注釈
スタンプのテキストとその境界線は、自動的にサイズ変更され、指定された矩形内で水平および垂直方向に中央に配置されます。
Annot.rect
は指定された 幅 に合わせて自動的に計算され、通常はこのパラメータよりも小さくなります。選択されるフォントは「Times Bold」で、テキストは大文字になります。
外観は
Annot.set_opacity()
を使用して変更でき、"stroke" 色を設定することができます(「fill」色はサポートされていません)。これは透かし画像を作成するために使用できます。一時的なPDFページ上に低い不透明度のスタンプ注釈を作成し、alpha=True でそれからピクスマップを作成し(おそらく回転させることもあります)、一時的なPDFページを破棄し、ターゲットのPDFに挿入するためにピクスマップを
insert_image()
で使用します。
- add_widget(widget)#
PDFのみ:ページにPDFフォームフィールド(ウィジェット)を追加します。これにより、PDFがフォームPDFに変換されます。ウィジェットにはさまざまなオプションがあるため、フォームフィールドの作成と更新の両方に使用する必要があるため、可能なPDFフィールド属性を含む新しいクラス Widget (ウィジェット) を開発しました。
- パラメータ:
widget (Widget (ウィジェット)) -- 事前に作成されている必要がある Widget (ウィジェット) オブジェクト。
- 戻り値:
ウィジェットアノテーション。
- delete_annot(annot)#
The removal will now include any bound 'Popup' or response annotations and related objects (changed in v1.16.6).
PDFのみ:ページから注釈を削除し、次の注釈を返します。
- パラメータ:
annot (Annot (注釈)) -- 削除するアノテーション。
- 戻り値の型:
- 戻り値:
削除された注釈の後に続く注釈。物理的な削除には、ガベージ> 0で新しいファイルに保存する必要があることを覚えておいてください。
- delete_widget(widget)#
PDFのみ:ページからフィールドを削除し、次のフィールドを返します。
- パラメータ:
widget (Widget (ウィジェット)) -- 削除するウィジェット。
- 戻り値の型:
- 戻り値:
削除されたウィジェットの後に続くウィジェット。物理的な削除には、ガベージ> 0で新しいファイルに保存する必要があることを覚えておいてください。
Show/hide history
(New in v1.18.4)
- delete_link(linkdict)#
PDF only: Delete the specified link from the page. The parameter must be an original item of
get_links()
, see get_links() エントリの説明. The reason for this is the dictionary's "xref" key, which identifies the PDF object to be deleted.- パラメータ:
linkdict (dict) -- 削除するリンクです。
- insert_link(linkdict)#
PDF only: Insert a new link on this page. The parameter must be a dictionary of format as provided by
get_links()
, see get_links() エントリの説明.- パラメータ:
linkdict (dict) -- 挿入するリンクです。
- update_link(linkdict)#
PDF only: Modify the specified link. The parameter must be a (modified) original item of
get_links()
, see get_links() エントリの説明. The reason for this is the dictionary's "xref" key, which identifies the PDF object to be changed.- パラメータ:
linkdict (dict) -- 変更するリンクです。
警告
URIリンク(
"kind": LINK_URI
)を更新/挿入する場合は、"uri"キーの値を必ず「http://」
、「https://」
、「file://」
、「ftp://」
、「mailto:」などの区別可能な文字列で始めるようにしてください。そうしないと、ブラウザや他の「コンシューマ」ソフトウェアによって、予期しないデフォルトの仮定が不要な動作につながる可能性があります。
- get_label()#
PDFのみ:ページのラベルを返します。
- 戻り値の型:
str
- 戻り値:
ローマ数字の「vii」などのラベル文字列、または定義されていない場合は ""。
Show/hide history
v1.18.6で新規追加
- get_links()#
ページの すべて のリンクを取得します。
- 戻り値の型:
list
- 戻り値:
A list of dictionaries. For a description of the dictionary entries, see get_links() エントリの説明. Always use this or the
Page.links()
method if you intend to make changes to the links of a page.
- links(kinds=None)#
ページのリンクをイテレーターとして返します。結果は:meth:
Page.get_links
のエントリと同じです。- パラメータ:
kinds (sequence) -- 1つ以上のリンク種別をダウン選択するための整数のシーケンス。デフォルトはすべてのリンクです。例:kinds=(fitz.LINK_GOTO,) は内部リンクのみを返します。
- 戻り値の型:
generator
- 戻り値:
各イテレーションごとの
Page.get_links()
のエントリ。
Show/hide history
v1.16.4で新規追加
- annots(types=None)#
ページの注釈をイテレーターとして返します。
- パラメータ:
types (sequence) -- 1つ以上の注釈タイプをダウン選択するための整数のシーケンス。デフォルトはすべての注釈です。例:
types=(fitz.PDF_ANNOT_FREETEXT, fitz.PDF_ANNOT_TEXT)
は「FreeText」および「Text」注釈のみを返します。- 戻り値の型:
generator
- 戻り値:
各イテレーションごとの Annot (注釈)。
注意
このジェネレータ内から アノテーションを安全に更新することはできません。これは、ほとんどの注釈の更新にはpage = doc.reload_page(page)を介してページを再読み込みする必要があるためです。この制限を回避するために、まず注釈のxref番号のリストを作成し、その後これらの番号を繰り返し処理します:
In [4]: xrefs = [annot.xref for annot in page.annots(types=[...])] In [5]: for xref in xrefs: ...: annot = page.load_annot(xref) ...: annot.update() ...: page = doc.reload_page(page) In [6]:
Show/hide history
v1.16.4で新規追加
- widgets(types=None)#
フォームフィールドのジェネレーターを返します。
- パラメータ:
types (sequence) -- 1つ以上のウィジェットタイプに選択を絞り込むための整数のシーケンス。デフォルトではすべてのフォームフィールドが対象です。例:
types=(fitz.PDF_WIDGET_TYPE_TEXT,)
を指定すると 'Text' フィールドのみが返されます。- 戻り値の型:
generator
- 戻り値:
各イテレーションでの Widget (ウィジェット)
Show/hide history
v1.16.4で新規追加
- write_text(rect=None, writers=None, overlay=True, color=None, opacity=None, keep_proportion=True, rotate=0, oc=0)#
PDF のみ: 1つ以上の TextWriter (テキストライター) オブジェクトのテキストをページに書き込みます。
- パラメータ:
rect (rect_like) -- テキストを配置する場所。省略した場合、テキストライターの矩形の合併が使用されます。
writers (sequence) -- 1つ以上の TextWriter (テキストライター) オブジェクトのタプル/リスト、または単一の TextWriter (テキストライター) です。
opacity (float) -- 透明度を設定し、テキストライターの値を上書きします。
color (sequ) -- テキストの色を設定し、テキストライターの値を上書きします。
overlay (bool) -- テキストを前景または背景に配置するかどうか。
keep_proportion (bool) -- アスペクト比を保持するかどうか。
rotate (float) -- テキストを任意の角度で回転します。
注釈
overlay、keep_proportion、rotate、oc パラメーターは
Page.show_pdf_page()
と同じ意味を持ちます。Show/hide history
v1.16.18 で追加された新機能です。
- insert_text(point, text, fontsize=11, fontname='helv', fontfile=None, idx=0, color=None, fill=None, render_mode=0, border_width=1, encoding=TEXT_ENCODING_LATIN, rotate=0, morph=None, stroke_opacity=1, fill_opacity=1, overlay=True, oc=0)#
PDFのみ:
point_like
point からテキストを挿入します。Shape.insert_text()
を参照してください。Show/hide history
v1.18.4 で変更
- insert_textbox(rect, buffer, fontsize=11, fontname='helv', fontfile=None, idx=0, color=None, fill=None, render_mode=0, border_width=1, encoding=TEXT_ENCODING_LATIN, expandtabs=8, align=TEXT_ALIGN_LEFT, charwidths=None, rotate=0, morph=None, stroke_opacity=1, fill_opacity=1, oc=0, overlay=True)#
PDF のみ:指定された
rect_like
の rect にテキストを挿入します。Shape.insert_textbox()
を参照してください。Show/hide history
v1.18.4 で変更
- insert_htmlbox(rect, text, *, css=None, scale_low=0, archive=None, rotate=0, oc=0, opacity=1, overlay=True)#
PDF only: Insert text into the specified rectangle. The method has similarities with methods
Page.insert_textbox()
andTextWriter.fill_textbox()
, but is much more powerful. This is achieved by letting a Story (ストーリー) object do all the required processing.Parameter
text
may be a string as in the other methods. But it will be interpreted as HTML source and may therefore also contain HTML language elements -- including styling. Thecss
parameter may be used to pass in additional styling instructions.Automatic line breaks are generated at word boundaries. The "soft hyphen" character
"­"
(or­
) can be used to cause hyphenation and thus may also cause line breaks. Forced line breaks however are only achievable via the HTML tag<br>
-"\n"
is ignored and will be treated like a space.With this method the following can be achieved:
Styling effects like bold, italic, text color, text alignment, font size or font switching.
The text may include arbitrary languages -- including right-to-left languages.
Scripts like Devanagari and several others in Asia have a highly complex system of ligatures, where two or more unicodes together yield one glyph. The Story uses the software package HarfBuzz , to deal with these things and produce correct output.
One can also include images via HTML tag
<img>
-- the Story will take care of the appropriate layout. This is an alternative option to insert images, compared toPage.insert_image()
.HTML tables (tag
<table>
) may be included in the text and will be handled appropriately.Links are automatically generated when present.
If content does not fit in the rectangle, the developer has two choices:
either only be informed about this (and accept a no-op, just like with the other textbox insertion methods),
or (
scale_low=0
- the default) scale down the content until it fits.
- パラメータ:
rect (rect_like) -- rectangle on page to receive the text.
text (str,Story) -- the text to be written. Can contain a mixture of plain text and HTML tags with styling instructions. Alternatively, a Story (ストーリー) object may be specified (in which case the internal Story generation step will be omitted). A Story must have been generated with all required styling and Archive information.
css (str) -- optional string containing additional CSS instructions. This parameter is ignored if
text
is a Story.scale_low (float) -- if necessary, scale down the content until it fits in the target rectangle. This sets the down scaling limit. Default is 0, no limit. A value of 1 means no down-scaling permitted. A value of e.g. 0.2 means maximum down-scaling by 80%.
archive (Archive) -- an Archive object that points to locations where to find images or non-standard fonts. If
text
refers to images or non-standard fonts, this parameter is required. This parameter is ignored iftext
is a Story.rotate (int) --
one of the values 0, 90, 180, 270. Depending on this, text will be filled:
0: top-left to bottom-right.
90: bottom-left to top-right.
180: bottom-right to top-left.
270: top-right to bottom-left.
oc (int) -- the xref of an
OCG
/OCMD
or 0. Please refer toPage.show_pdf_page()
for details.opacity (float) -- set the fill and stroke opacity of the content. Only values
0 <= opacity < 1
are considered.overlay (bool) -- put the text in front of other content. Please refer to
Page.show_pdf_page()
for details.
- 戻り値:
A tuple of floats
(spare_height, scale)
.spare_height
: -1 if content did not fit, else >= 0. It is the height of the unused (still available) rectangle stripe. Positive only if scale = 1 (no down-scaling happened).scale
: down-scaling factor, 0 < scale <= 1.
Please refer to examples in this section of the recipes: How to Fill a Box with HTML Text.
Show/hide history
New in v1.23.8; rebased-only.
New in v1.23.9:
opacity
parameter.
Drawing Methods
- draw_line(p1, p2, color=(0,), width=1, dashes=None, lineCap=0, lineJoin=0, overlay=True, morph=None, stroke_opacity=1, fill_opacity=1, oc=0)#
PDF のみ:p1 から p2 までの直線を描画します(
point_like
s)。Shape.draw_line()
を参照してください。Show/hide history
v1.18.4 で変更
- draw_zigzag(p1, p2, breadth=2, color=(0,), width=1, dashes=None, lineCap=0, lineJoin=0, overlay=True, morph=None, stroke_opacity=1, fill_opacity=1, oc=0)#
PDF のみ:p1 から p2 までのジグザグ線を描画します(
point_like
s)。Shape.draw_zigzag()
を参照してください。Show/hide history
v1.18.4 で変更
- draw_squiggle(p1, p2, breadth=2, color=(0,), width=1, dashes=None, lineCap=0, lineJoin=0, overlay=True, morph=None, stroke_opacity=1, fill_opacity=1, oc=0)#
PDF のみ:p1 から p2 までの波線(うねり)を描画します(
point_like
s)。Shape.draw_squiggle()
を参照してください。Show/hide history
v1.18.4 で変更
- draw_circle(center, radius, color=(0,), fill=None, width=1, dashes=None, lineCap=0, lineJoin=0, overlay=True, morph=None, stroke_opacity=1, fill_opacity=1, oc=0)#
PDF のみ:center を中心に、半径 radius の円を描画します:data:
point_like
。Shape.draw_circle()
を参照してください。Show/hide history
v1.18.4 で変更
- draw_oval(quad, color=(0,), fill=None, width=1, dashes=None, lineCap=0, lineJoin=0, overlay=True, morph=None, stroke_opacity=1, fill_opacity=1, oc=0)#
PDF のみ:指定された
rect_like
またはquad_like
内に楕円を描画します。Shape.draw_oval()
を参照してください。Show/hide history
v1.18.4 で変更
- draw_sector(center, point, angle, color=(0,), fill=None, width=1, dashes=None, lineCap=0, lineJoin=0, fullSector=True, overlay=True, closePath=False, morph=None, stroke_opacity=1, fill_opacity=1, oc=0)#
PDFのみ: 円形セクターを描画し、オプションで円の中心とアークを接続します(パイの一部のように)。
Shape.draw_sector()
を参照してください。Show/hide history
v1.18.4 で変更
- draw_polyline(points, color=(0,), fill=None, width=1, dashes=None, lineCap=0, lineJoin=0, overlay=True, closePath=False, morph=None, stroke_opacity=1, fill_opacity=1, oc=0)#
PDFのみ: 一連の
point_like
s ポイントによって定義された接続された複数のラインを描画します。Shape.draw_polyline()
を参照してください。Show/hide history
v1.18.4 で変更
- draw_bezier(p1, p2, p3, p4, color=(0,), fill=None, width=1, dashes=None, lineCap=0, lineJoin=0, overlay=True, closePath=False, morph=None, stroke_opacity=1, fill_opacity=1, oc=0)#
PDFのみ: 制御ポイント p2 および p3 を使用して、p1 から p4 へのキュービックベジエ曲線を描画します(すべてのポイントは
point_like
です)。Shape.draw_bezier()
を参照してください。Show/hide history
v1.18.4 で変更
- draw_curve(p1, p2, p3, color=(0,), fill=None, width=1, dashes=None, lineCap=0, lineJoin=0, overlay=True, closePath=False, morph=None, stroke_opacity=1, fill_opacity=1, oc=0)#
PDFのみ: これは draw_bezier() の特別なケースです。
Shape.draw_curve()
を参照してください。Show/hide history
v1.18.4 で変更
- draw_rect(rect, color=(0,), fill=None, width=1, dashes=None, lineCap=0, lineJoin=0, overlay=True, morph=None, stroke_opacity=1, fill_opacity=1, radius=None, oc=0)#
PDFのみ: 四角形を描画します。
Shape.draw_rect()
を参照してください。Show/hide history
v1.18.4 で変更
v1.22.0で変更:パラメーター radius を追加しました。
- draw_quad(quad, color=(0,), fill=None, width=1, dashes=None, lineCap=0, lineJoin=0, overlay=True, morph=None, stroke_opacity=1, fill_opacity=1, oc=0)#
PDFのみ: 四辺形を描画します。
Shape.draw_quad()
を参照してください。Show/hide history
v1.18.4 で変更
- insert_font(fontname='helv', fontfile=None, fontbuffer=None, set_simple=False, encoding=TEXT_ENCODING_LATIN)#
PDFのみ: テキスト出力メソッドで使用する新しいフォントを追加し、その
xref
を返します。ファイルにまだ存在しない場合、フォントの定義が追加されます。組み込みのBase14_Fonts
および CJK フォントがサポートされており、「予約済み」 フォント名を介して使用できます。フォントはファイルパスまたはフォントファイルのイメージを含むメモリ領域として提供することもできます。- パラメータ:
fontname (str) --
このフォントをこのページ上でテキスト出力する際に参照される名前。一般的に、ここで「自由な」選択ができます(ただし、Adobe PDFリファレンス、ページ16、セクション7.3.5を参照して正当なPDF名の形式的な説明を確認してください)。ただし、
Base14_Fonts
またはCJKフォントのいずれかと一致する場合、fontfile および fontbuffer は 無視されます。言い換えれば、フォントを fontfile / fontbuffer 経由で挿入し、予約されたフォント名も指定することはできません。
注釈
予約されたフォント名は、大文字と小文字の組み合わせで指定でき、それでも適切な組み込みフォントの定義に一致します。フォント名「helv」、「Helv」、「HELV」、「Helvetica」などはすべて同じフォント定義「Helvetica」につながります。ただし、ページの観点からはこれらは 異なる参照 です。同じフォントの異なる エンコーディング バリアント(ラテン、ギリシャ、キリル文字など)をページ上で使用する場合、この事実を利用できます。
fontfile (str) -- フォントファイルへのパス。使用する場合、fontname は すべての予約済みの名前と異なる必要があります。
fontbuffer (bytes/bytearray) -- フォントファイルのメモリイメージ。使用する場合、fontname は すべての予約済みの名前と異なる 必要があります。通常、このパラメーターは
Font.buffer
を介してサポート/利用可能な Font (フォント) に使用されます。set_simple (int) -- fontfile / fontbuffer ケースにのみ適用可能:「シンプル」フォントとしての扱いを強制します。つまり、文字コードが255までしか使用しないフォントです。
encoding (int) --
Base14_Fonts
の「Helvetica」、「Courier」、「Times」セットにのみ適用可能。利用可能なエンコーディングのうち、ラテン(0)、キリル文字(2)、ギリシャ文字(1)のいずれかを選択します。「Symbol」と「ZapfDingBats」についてはデフォルト(0 = ラテン)のみを使用してください。
- Rytpe:
int
- 戻り値:
インストールされたフォントの
xref
。
注釈
組み込みフォントはフォントファイルの追加を必要とせず、結果として生成されるPDFファイルは小さく保たれます。ただし、PDFビューアソフトウェアは適切な外観を生成する責任があり、それぞれがこれをどのように行うかには違い があります。これは特にCJKフォントに関して当てはまります。しかし、シンボルとZapfDingbatsも一部のケースで正しく扱われていないことがあります。以下は Font Names とそれに対応するインストールされた Base Font 名です:
ベース14フォント [1]
フォント名
インストールされたベースフォント
コメント
helv
Helvetica
通常
heit
Helvetica-Oblique
斜体
hebo
Helvetica-Bold
太字
hebi
Helvetica-BoldOblique
太字斜体
cour
Courier
通常
coit
Courier-Oblique
斜体
cobo
Courier-Bold
太字
cobi
Courier-BoldOblique
太字斜体
tiro
Times-Roman
通常
tiit
Times-Italic
斜体
tibo
Times-Bold
太字
tibi
Times-BoldItalic
太字斜体
symb
Symbol
zadb
ZapfDingbats
CJKフォント [2] (中国、日本、韓国)
フォント名
インストールされたベースフォント
コメント
china-s
Heiti
簡体字中国語
china-ss
Song
簡体字中国語(セリフ)
china-t
Fangti
繁体字中国語
china-ts
Ming
繁体字中国語(セリフ)
japan
Gothic
Japanese
japan-s
Mincho
Japanese (serif)
korea
Dotum
Korean
korea-s
Batang
Korean (serif)
- insert_image(rect, *, alpha=-1, filename=None, height=0, keep_proportion=True, mask=None, oc=0, overlay=True, pixmap=None, rotate=0, stream=None, width=0, xref=0)#
PDFのみ:指定された矩形内に画像を配置します。画像はすでにPDF内に存在するか、ピクスマップ、ファイル、またはメモリ領域から取得できます。
- パラメータ:
rect (rect_like) -- 画像を配置する場所。有限で空でない必要があります。
alpha (int) -- deprecated and ignored.
filename (str) -- 画像ファイルの名前(MuPDFでサポートされているすべての形式 – サポートされている入力画像フォーマット を参照)。
height (int) --
keep_proportion (bool) -- maintain the aspect ratio of the image.
mask (bytes,bytearray,io.BytesIO) -- image in memory -- to be used as image mask (alpha values) for the base image. When specified, the base image must be provided as a filename or a stream -- and must not be an image that already has a mask.
oc (int) -- (
xref
) make image visibility dependent on thisOCG
orOCMD
. Ignored after the first of multiple insertions. The property is stored with the generated PDF image object and therefore controls the image's visibility throughout the PDF.overlay -- see 共通パラメータ.
pixmap (Pixmap) -- 画像を含むピクスマップ。
rotate (int) -- rotate the image. Must be an integer multiple of 90 degrees. Positive values rotate anti-clockwise. If you need a rotation by an arbitrary angle, consider converting the image to a PDF (
Document.convert_to_pdf()
) first and then usePage.show_pdf_page()
instead.stream (bytes,bytearray,io.BytesIO) -- メモリ内の画像(MuPDFでサポートされているすべての形式 – サポートされている入力画像フォーマット を参照)。
width (int) --
xref (int) -- the
xref
of an image already present in the PDF. If given, parametersfilename
, Pixmap,stream
,alpha
andmask
are ignored. The page will simply receive a reference to the existing image.
- 戻り値:
The
xref
of the embedded image. This can be used as thexref
argument for very significant performance boosts, if the image is inserted again.
この例では、ドキュメントのすべてのページに同じ画像を配置します:
>>> doc = fitz.open(...) >>> rect = fitz.Rect(0, 0, 50, 50) # put thumbnail in upper left corner >>> img = open("some.jpg", "rb").read() # an image file >>> img_xref = 0 # first execution embeds the image >>> for page in doc: img_xref = page.insert_image(rect, stream=img, xref=img_xref, 2nd time reuses existing image ) >>> doc.save(...)
注釈
The method detects multiple insertions of the same image (like in the above example) and will store its data only on the first execution. This is even true (although less performant), if using the default
xref=0
.このメソッドは、ファイルを開く前に同じ画像がすでにファイルの一部であるかどうかを検出できません。
このメソッドを使用して、ページの背景または前景画像(著作権表示や透かしのようなもの)を提供できます。ただし、前景に透明な画像が必要な場合は、そのことを覚えておいてください...
The image may be inserted uncompressed, e.g. if a Pixmap is used or if the image has an alpha channel. Therefore, consider using
deflate=True
when saving the file. In addition, there are ways to control the image size -- even if transparency comes into play. Have a look at PDFページに画像を追加する方法.The image is stored in the PDF at its original quality level. This may be much better than what you need for your display. Consider decreasing the image size before insertion -- e.g. by using the pixmap option and then shrinking it or scaling it down (see Pixmap chapter). The PIL method
Image.thumbnail()
can also be used for that purpose. The file size savings can be very significant.Another efficient way to display the same image on multiple pages is another method:
show_pdf_page()
. ConsultDocument.convert_to_pdf()
for how to obtain intermediary PDFs usable for that method.
Show/hide history
v1.14.1で変更:デフォルトでは、画像はアスペクト比を保持します
Changed in v1.14.11: Added args
keep_proportion
,rotate
.Changed in v1.14.13:
The image is now always placed centered in the rectangle, i.e. the centers of image and rectangle are equal.
Added support for
stream
asio.BytesIO
.
v1.17.6で変更:挿入矩形はもはやページの
Page.cropbox
[5] と非空の交差を持つ必要はありません。Changed in v1.18.1: Added
mask
arg.Changed in v1.18.3: Added
oc
arg.Changed in v1.18.13:
Changed in v1.19.3: deprecate and ignore
alpha
arg.
- replace_image(xref, filename=None, pixmap=None, stream=None)#
xrefで指定された画像を別の画像で置き換えます。
- パラメータ:
filename
、Pixmap、stream
の引数は、特にPage.insert_image()
での意味と同じです。特に、これらのうちの1つだけを指定する必要があります。これは グローバルな置換 です:新しい画像は、古い画像がファイル全体で表示されていた場所でも表示されます。
このメソッドは主に技術的な目的で存在しています。典型的な使用例には、大きな画像を解像度の低いバージョン、カラーではなくグレースケールなど、より小さなバージョンで置き換えることが含まれます。または透明度を変更することもあります。
Show/hide history
v1.21.0で新たに追加
- delete_image(xref)#
画像のxrefを削除します。これはわずかに誤解を招くかもしれませんが、実際には、画像は上記の
Page.replace_image()
を使用して小さな透明な Pixmap で置き換えられます。しかし、視覚的な効果は同等です。- パラメータ:
xref (int) -- 画像の
xref
。
これは グローバルな置換です: 新しい画像は、古い画像がファイル全体で表示されていた場所でも表示されなくなります。
Page.get_images()
、Page.get_image_info()
、またはPage.get_text()
などのメソッドを使用してページの画像を調査/抽出する場合、置き換えられた「ダミー」画像は次のように検出されます`(45, 47, 1, 1, 8, 'DeviceGray', '', 'Im1', 'FlateDecode')` 、また同じ境界ボックスをページ上に「覆う」ように見えます。Show/hide history
v1.21.0で新たに追加
- get_text(option, *, clip=None, flags=None, textpage=None, sort=False, delimiters=None)#
Retrieves the content of a page in a variety of formats. This is a wrapper for multiple TextPage (テキストページ) methods by choosing the output option
opt
as follows:“text” –
TextPage.extractTEXT()
、デフォルト"blocks" --
TextPage.extractBLOCKS()
"words" --
TextPage.extractWORDS()
"html" --
TextPage.extractHTML()
"xhtml" --
TextPage.extractXHTML()
"xml" --
TextPage.extractXML()
"dict" --
TextPage.extractDICT()
"json" --
TextPage.extractJSON()
"rawdict" --
TextPage.extractRAWDICT()
"rawjson" --
TextPage.extractRAWJSON()
- パラメータ:
opt (str) --
要求される形式を示す文字列、上記のいずれか。大文字と小文字の組み合わせがサポートされています
Values "words" and "blocks" are also accepted (changed in v1.16.3).
clip (rect-like) -- restrict extracted text to this rectangle. If None, the full page is taken. Has no effect for options "html", "xhtml" and "xml". (New in v1.17.7)
flags (int) -- indicator bits to control whether to include images or how text should be handled with respect to white spaces and
ligatures
. See テキスト抽出フラグ for available indicators and テキスト抽出フラグのデフォルト値 for default settings. (New in v1.16.2)textpage -- use a previously created TextPage (テキストページ). This reduces execution time very significantly: by more than 50% and up to 95%, depending on the extraction option. If specified, the 'flags' and 'clip' arguments are ignored, because they are textpage-only properties. If omitted, a new, temporary textpage will be created. (New in v1.19.0)
sort (bool) -- sort the output by vertical, then horizontal coordinates. In many cases, this should suffice to generate a "natural" reading order. Has no effect on (X)HTML and XML. Output option "words" sorts by
(y1, x0)
of the words' bboxes. Similar is true for "blocks", "dict", "json", "rawdict", "rawjson": they all are sorted by(y1, x0)
of the resp. block bbox. If specified for "text", then internally "blocks" is used. (New in v1.19.1)delimiters (str) -- use these characters as additional word separators with the "words" output option (ignored otherwise). By default, all white spaces (including non-breaking space
0xA0
) indicate start and end of a word. Now you can specify more characters causing this. For instance, the default will return"john.doe@outlook.com"
as one word. If you specifydelimiters="@."
then the four words"john"
,"doe"
,"outlook"
,"com"
will be returned. Other possible uses include ignoring punctuation charactersdelimiters=string.punctuation
. The "word" strings will not contain any delimiting character. (New in v1.23.5)
- 戻り値の型:
str, list, dict
- 戻り値:
ページの内容を表す文字列、リスト、または辞書。詳細については対応するTextPageメソッドを参照してください。
注釈
このメソッドを、any supported document type からTEXT、HTML、XHTML、またはXMLドキュメントのいずれかに変換する ドキュメント変換ツール として使用できます。
The inclusion of text via the clip parameter is decided on a by-character level: a character becomes part of the output, if its bbox is contained in clip (changed in v1.18.2). This deviates from the algorithm used in redaction annotations: a character will be removed if its bbox intersects any redaction annotation.
Show/hide history
v1.19.0で変更:TextPage (テキストページ) パラメータを追加
v1.19.1で変更:
sort
パラメータを追加v1.19.6で変更:各メソッドごとのデフォルトフラグを定義するための新しい定数を追加
Changed in v1.23.5: added
delimiters
parameter
- get_textbox(rect, textpage=None)#
指定された矩形に含まれるテキストを取得します。
- パラメータ:
rect (rect-like) -- 矩形のようなもの。
textpage -- 使用する TextPage (テキストページ)。省略した場合、新しい一時的なテキストページが作成されます。
- 戻り値:
a string with interspersed linebreaks where necessary. It is based on dedicated code (changed in v1.19.0). A tyical use is checking the result of
Page.search_for()
:>>> rl = page.search_for("currency:") >>> page.get_textbox(rl[0]) 'Currency:' >>>
Show/hide history
新機能 v1.17.7
v1.19.0 で変更: TextPage (テキストページ) パラメータを追加
- get_textpage(clip=None, flags=3)#
ページ用の TextPage (テキストページ) を作成します
- パラメータ:
flags (int) -- 後続のテキスト抽出と検索で使用可能なコンテンツを制御する指示ビット –
Page.get_text()
のパラメータを参照してください。clip (rect-like) -- restrict extracted text to this area. (New in v1.17.7)
- 戻り値:
Show/hide history
v1.16.5 で新機能。
v1.17.7 で変更:
clip
パラメータが導入されました。
- get_textpage_ocr(flags=3, language='eng', dpi=72, full=False, tessdata=None)#
Optical Character Recognition (OCR) technology can be used to extract text data for documents where text is in a raster image format throughout the page. Use this method to OCR a page for text extraction.
This method returns a TextPage (テキストページ) for the page that includes OCRed text. MuPDF will invoke Tesseract-OCR if this method is used. Otherwise this is a normal TextPage (テキストページ) object.
- パラメータ:
flags (int) -- 後続のテキスト抽出と検索に使用可能なコンテンツを制御する指示ビット –
Page.get_text()
のパラメータを参照してください。language (str) -- 期待される言語。複数の言語が期待される場合は "+" で区切って指定します。たとえば英語とスペイン語の場合は "eng+spa" です。
dpi (int) -- インチ当たりのドット数で指定された解像度。認識品質(および実行時間)に影響を与えます。
full (bool) -- ページ全体を OCR するか、表示された画像のみを OCR するかを指定します。
tessdata (str) -- Tesseract の言語サポートフォルダ
tessdata
の名前。省略した場合、この情報は環境変数TESSDATA_PREFIX
として存在している必要があります。tessdata を取得する関数get_tessdata()
によって決定できます。
注釈
このメソッドは clip パラメータをサポート していない ため、OCR は常に完全なページ矩形に対して行われます
- 戻り値:
TextPage (テキストページ)。実行時間は
Page.get_textpage()
よりも大幅に長くなる場合があります。フルページの OCR の場合、すべてのテキスト は Tesseract の "GlyphlessFont" になります。部分的な OCR の場合、通常のテキストはそのプロパティを保持し、画像から来たテキストのみが GlyphlessFont になります。
注釈
OCRed textは、PyMuPDFのテキスト抽出と検索でのみ利用可能であり、その TextPage (テキストページ) パラメータがこのメソッドの出力を指定している場合にのみ利用できます。
このJupyter ノートブックは、OCRテキストページを使用する例を説明します。
Show/hide history
v1.19.0 で新機能
v1.19.1 で変更: ページのフルと部分的な OCR をサポート
- get_drawings(extended=False)#
ページのベクトルグラフィックスを返します。これらは線、四角形、四角形または曲線を描画するための命令で、色、透明度、線の幅、点線などのプロパティを含みます。代替用語は「ラインアート」と「ドローイング」です。
- 戻り値:
辞書のリスト。各辞書アイテムには、同じプロパティ(色、破線など)を持つ1つ以上の単一の描画コマンドが含まれます。これらはPDFでは "path" と呼ばれ、ここではその名前を採用していますが、このメソッドは すべてのドキュメントタイプに対して機能します。
fill、stroke、fill-strokeパスのパス辞書は、Shape(シェイプ) クラスと互換性があるように設計されています。次のキーがあります:
キー
値
closePath
Shape(シェイプ) のパラメーターと同じです。
color
ストロークカラー(Shape(シェイプ) を参照)。
dashes
破線の仕様(Shape(シェイプ) を参照)。
even_odd
領域のオーバーラップの塗りつぶし色(Shape(シェイプ) を参照)。
fill
塗りつぶしカラー(Shape(シェイプ) を参照)。
items
描画コマンド(直線、四角形、四角形、曲線など)のリスト。
lineCap
3つの数値からなるタプル。出力時に Shape(シェイプ) との最大値を使用します。
lineJoin
Shape(シェイプ) のパラメーターと同じです。
fill_opacity
fill color transparency (see Shape(シェイプ)). (New in v1.18.17)
stroke_opacity
stroke color transparency (see Shape(シェイプ)). (New in v1.18.17)
rect
このパスでカバーされるページ領域。情報のみ。
layer
name of applicable Optional Content Group. (New in v1.22.0)
level
the hierarchy level if
extended=True
. (New in v1.22.0)seqno
command number when building page appearance. (New in v1.19.0)
type
type of this path. (New in v1.18.17)
width
Stroke line width. (see Shape(シェイプ)).
Key
"opacity"
has been replaced by the new keys"fill_opacity"
and"stroke_opacity"
. This is now compatible with the corresponding parameters ofShape.finish()
. (Changed in v1.18.17)グループやクリップ以外のパスに対して、キー
"type"
は次のいずれかの値を取ります:"f" - これは fill-only のパスです。この操作に関連するキーの値のみが意味を持ち、適用されないものは値が None で存在します。:
"color"
、"lineCap"
、"lineJoin"、
"width"、
"closePath"、
"dashes"` は無視すべきです。"s" - これは stroke-only のパスです。以前と同様に、キー
"fill"
は値が None で存在します。"fs" - これは fill と stroke の組み合わせ操作を実行するパスです
path["items"]
の各アイテムは、次のいずれかです:("l", p1, p2)
- p1 から p2 への直線(Point (ポイント) オブジェクト)。("c", p1, p2, p3, p4)
- p1 から p4 へ の三次ベジエ曲線(p2 と p3 は制御点です)。すべてのオブジェクトは Point (ポイント) タイプです。("re", rect, orientation)
- a Rect (矩形). Multiple rectangles within the same path are now detected (changed in v1.18.17). Integerorientation
is 1 resp. -1 indicating whether the enclosed area is rotated left (1 = anti-clockwise), or resp. right [7] (changed in v1.19.2).("qu", quad)
- a Quad (クアッド). 3 or 4 consecutive lines are detected to actually represent a Quad (クアッド) (changed in v1.19.2:). (New in v1.18.17)
クラス Shape(シェイプ) を使用すると、通常の、あまり洗練されていない状況で、高い忠実度で元の図面を別の(PDF)ページに再作成できるはずです。制約事項に関する以下のコメントをご覧ください。コーディングのドラフトは、FAQ の「図面の抽出」章のセクションにあります。
Specifying
extended=True
significantly alters the output. Most importantly, new dictionary types are present: "clip" and "group". All paths will now be organized in a hierarchic structure which is encoded by the new integer key "level", the hierarchy level. Each group or clip establishes a new hierarchy, which applies to all subsequent paths having a larger level value. (New in v1.22.0)前任者よりも小さいレベル値を持つパスは、少なくとも前の階層レベルのスコープを終了します。前のクリップと同じレベルの "clip" パスは、そのクリップのスコープを終了します。同様に、グループも同じです。これは、次の例で最もよく説明されます:
+------+------+--------+------+--------+ | line | lvl0 | lvl1 | lvl2 | lvl3 | +------+------+--------+------+--------+ | 0 | clip | | | | | 1 | | fill | | | | 2 | | group | | | | 3 | | | clip | | | 4 | | | | stroke | | 5 | | | fill | | ends scope of clip in line 3 | 6 | | stroke | | | ends scope of group in line 2 | 7 | | clip | | | | 8 | fill | | | | ends scope of line 0 +------+------+--------+------+--------+
行0の「clip」は行7を含む行全体に適用されます。行2の「group」は行3から5までの行に適用され、行3の「clip」は行4にのみ適用されます。
行4の「stroke」は行2の「group」と行3の「clip」(それ自体が行0の「clip」のサブセットです)の制御下にあります。
「clip」 辞書。その値(特に「scissor」)は、後続の辞書が「level」の値が大きい限り、有効で適用されます。
キー
値
closePath
「stroke」または「fill」の辞書と同じ
even_odd
「stroke」または「fill」の辞書と同じ
items
「stroke」または「fill」の辞書と同じ
rect
「stroke」または「fill」の辞書と同じ
layer
「stroke」または「fill」の辞書と同じ
level
「stroke」または「fill」の辞書と同じ
scissor
クリップ矩形
type
"clip"
「group」辞書。その値は、後続の辞書が「level」の値が大きい限り、有効で適用されます。同じレベルまたはそれ以下の辞書がこのグループを終了します。
キー
値
rect
「stroke」または「fill」の辞書と同じ
layer
「stroke」または「fill」の辞書と同じ
level
「stroke」または「fill」の辞書と同じ
isolated
(ブール)このグループが孤立しているかどうか
knockout
(ブール)これが「Knockout Group」であるかどうか
blendmode
BlendModeの名前、デフォルトは「Normal」
opacity
範囲[0、1]内の浮動小数点値
type
"group"
注釈
このメソッドは、
Page.get_cdrawings()
の出力に基づいています。これははるかに高速ですが、出力の処理には多少の注意が必要です。Show/hide history
v1.18.0で新規追加
v1.18.17で変更
v1.19.0で変更: “seqno”キーを追加、“clippings”キーを削除
v1.19.1で変更: “color” / “fill”キーは常にRGBタプルまたはNoneのいずれかであるように変更。これにより、異常なカラースペースに起因する問題が解消されます。
v1.19.2で変更: "re" アイテムでカバーされる領域の "orientation" を示すインジケーターを追加
v1.22.0で変更: 新しいキー
"layer"
を追加。これにはパスのオプションコンテンツグループの名前が含まれます(またはNone)。v1.22.0で変更: クリッピングとグループパスも返すようにするためのパラメーター
extended
を追加
- get_cdrawings(extended=False)#
ページ上のベクトルグラフィックスを抽出します。技術的な違いを除いて、
Page.get_drawings()
と機能的に同等ですが、はるかに高速です:各パスタイプには関連するキーのみ含まれます。たとえば、ストロークパスには
"fill"
カラーキーはありません。Page.get_drawings()
メソッドのコメントを参照してください。座は
point_like
、rect_like
、quad_like
の tuples として与えられます。Point (ポイント)、Rect (矩形)、Quad (クアッド) オブジェクトとしてではなく。
性能が懸念される場合、このメソッドを使用することを検討してください。バージョン1.18.17より前と比較して、応答時間が大幅に短縮されるはずです。以前は2秒かかったページが、このメソッドを使用すると200ミリ秒で完了する場合もあります。
Show/hide history
新機能(v1.18.17)
v1.19.0で変更:「clippings」キーを削除、新たに「seqno」キーを追加。
v1.19.1で変更:常にRGBカラータプルを生成します。
v1.22.0で変更:新たに「layer」というキーが追加され、パスのオプションコンテンツグループの名前(またはNone)が含まれます。
Changed in v1.22.0: added parameter
extended
to also return clipping paths.
- get_fonts(full=False)#
PDFのみ:ページで参照されているフォントのリストを返します。
Document.get_page_fonts()
のラッパーです。
- get_images(full=False)#
PDFのみ:ページで参照されているイメージのリストを返します。
Document.get_page_images()
のラッパーです。
- get_image_info(hashes=False, xrefs=False)#
ページ上に表示されているすべてのイメージに関するメタ情報辞書のリストを返します。これはすべての文書タイプで機能します。技術的には、これは
Page.get_text()
の辞書出力のサブセットであり、画像のバイナリコンテンツとページ上のテキストは無視されます。- パラメータ:
hashes (bool) -- Compute the MD5 hashcode for each encountered image, which allows identifying image duplicates. This adds the key
"digest"
to the output, whose value is a 16 bytebytes
object. (New in v1.18.13)xrefs (bool) -- PDF only. Try to find the
xref
for each image. Implieshashes=True
. Adds the"xref"
key to the dictionary. If not found, the value is 0, which means, the image is either "inline" or otherwise undetectable. Please note that this option has an extended response time, because the MD5 hashcode will be computed at least two times for each image with an xref. (New in v1.18.13)
- 戻り値の型:
list[dict]
- 戻り値:
辞書のリスト。これには、ページに表示されているイメージに関する情報が含まれます。
Page.get_text()
で含まれている画像ブロックとは異なり、画像の binary content は読み込まれないため、メモリの使用量が大幅に削減されます。辞書のレイアウトは、ページ.get_text("dict")内のイメージブロックと似ています。キー
値
number
ブロック番号 (整数)
bbox
ページ上の画像の境界ボックス、
rect_like
width
元の画像の幅 (整数)
height
元の画像の高さ (整数
cs-name
カラースペース名 (文字列)
colorspace
colorspace.n (整数)
xres
x方向の解像度 (整数)
yres
y方向の解像度 (整数)
bpc
コンポーネントごとのビット数 (整数)
size
画像が占めるストレージ容量 (整数)
digest
MD5ハッシュコード(バイト)、hashes がtrueの場合
xref
画像の
xref
または0、xrefs がtrueの場合transform
画像の境界ボックスをbboxに変換するための行列、
matrix_like
同じ画像の複数の出現は常に報告されます。digestの値を比較して重複を検出できます。
Show/hide history
New in v1.18.11
Changed in v1.18.13: added image MD5 hashcode computation and
xref
search.
- get_xobjects()#
PDFのみ:ページで参照されているフォームXObjectのリストを返します。
Document.get_page_xobjects()
のラッパーです。
- get_image_rects(item, transform=False)#
PDFのみ:埋め込み画像の境界ボックスと変換行列を返します。これは
Page.get_image_bbox()
の改良バージョンで、次の違いがあります:画像が どのように 呼び出されるかに制限はありません(ページまたはそのフォームXObjectのいずれかによって)。結果は常に完全かつ正確です。
結果は Rect (矩形) または(Rect (矩形)、Matrix (マトリックス))オブジェクトのリストです(transform に応じて異なります)。各リスト項目は、ページ上の画像の1つの場所を表します。
Page.get_image_bbox()
では複数の出現を検出できない場合があります。このメソッドは、
xrefs=True
でPage.get_image_info()
を呼び出すため、Page.get_image_bbox()
よりも明らかに長い応答時間がかかります。
- パラメータ:
item (list,str,int) --
Page.get_images()
のリストアイテム、そのようなアイテムの参照 name エントリ(item[7])、または画像のxref
。transform (bool) -- 画像の矩形をbboxに変換するために使用される行列も返すかどうか。trueの場合、タプル
(bbox, matrix)
が返されます。
- 戻り値の型:
list
- 戻り値:
ページ上の各画像出現に対する境界ボックスとそれに対応する変換行列。アイテムがページ上にない場合、空のリスト
[]
が返されます。
Show/hide history
New in v1.18.13
- get_image_bbox(item, transform=False)#
PDFのみ:埋め込まれたイメージの境界ボックスと変換行列を返します。
- パラメータ:
item (list,str) --
Page.get_images()
のリストのアイテムで full=True が指定されているもの、またはそのようなアイテムの参照名 name エントリ、つまりitem[-3](またはitem[7])。transform (bool) -- return the matrix used to transform the image rectangle to the bbox on the page (new in v1.18.11). Default is just the bbox. If true, then a tuple
(bbox, matrix)
is returned.
- 戻り値の型:
- 戻り値:
イメージの境界ボックス - オプションでその変換行列も。
Show/hide history
(Changed in v1.16.7): If the page in fact does not display this image, an infinite rectangle is returned now. In previous versions, an exception was raised. Formally invalid parameters still raise exceptions.
(Changed in v1.17.0): Only images referenced directly by the page are considered. This means that images occurring in embedded PDF pages are ignored and an exception is raised.
(Changed in v1.18.5): Removed the restriction introduced in v1.17.0: any item of the page's image list may be specified.
(Changed in v1.18.11): Partially re-instated a restriction: only those images are considered, that are either directly referenced by the page or by a Form XObject directly referenced by the page.
(Changed in v1.18.11): Optionally also return the transformation matrix together with the bbox as the tuple
(bbox, transform)
.
注釈
Page.get_images()
には「不要な」エントリが含まれている場合があることに注意してください。これはPDF作成者によって意図的に設定されたものであり、エラーではありません。この場合、例外は発生しませんが、無限の矩形が返されます。このような状況を回避するには、このメソッドの前にPage.clean_contents()
を実行することができます。イメージの「変換行列」は、
bbox / transform == fitz.Rect(0, 0, 1, 1)
という式が真であるための行列であり、詳細はこちらを参照してください:画像変換行列。
Show/hide history
変更点 v1.18.11:イメージの変換行列を返すようになりました
- get_svg_image(matrix=fitz.Identity, text_as_path=True)#
ページからSVGイメージを作成します。現在、フルページのイメージのみがサポートされています。
- パラメータ:
matrix (matrix_like) -- 行列、デフォルトは Identity (アイデンティティ) です。
text_as_path (bool) -- -- controls how text is represented. True outputs each character as a series of elementary draw commands, which leads to a more precise text display in browsers, but a very much larger output for text-oriented pages. Display quality for False relies on the presence of the referenced fonts on the current system. For missing fonts, the internet browser will fall back to some default -- leading to unpleasant appearances. Choose False if you want to parse the text of the SVG. (New in v1.17.5)
- 戻り値:
UTF-8エンコードされた文字列で、イメージを含みます。 SVGにはXML構文があるため、テキストファイルに保存でき、標準の拡張子は
.svg
です。注釈
PDFの場合、メソッドを使用する前に、ページのCropBoxを変更して「フルページイメージのみ」制限を回避できます。
- get_pixmap(*, matrix=fitz.Identity, dpi=None, colorspace=fitz.csRGB, clip=None, alpha=False, annots=True)#
ページからピクスマップを作成します。おそらく、Pixmap を作成するために最も頻繁に使用されるメソッドでしょう。
すべてのパラメータは keyword-only. です。
- パラメータ:
matrix (matrix_like) -- デフォルトは Identity (アイデンティティ) です。
dpi (int) -- desired resolution in x and y direction. If not
None
, the"matrix"
parameter is ignored. (New in v1.19.2)colorspace (str or Colorspace (カラースペース)) -- 所望のカラースペース、"GRAY"、"RGB"、または"CMYK"のいずれか(大文字/小文字を区別しない)。または、Colorspace (カラースペース) のように、事前定義されたもののいずれかを指定できます:
csGRAY
、csRGB
、csCMYK
。clip (irect_like) -- ページの矩形とこの領域の交差に描画を制限します。
alpha (bool) --
透明チャネルを追加するかどうか。本当に透明性が必要でない場合は、常にデフォルトの False を受け入れてください。これにより、メモリ(RGBの場合25%…ピクスマップは通常大きいです!)と処理時間が大幅に節約されます。また、画像がレンダリングされる方法についても重要な違いに注意してください: True の場合、ピクスマップのサンプル領域は0x00で事前クリアされます。これにより、ページが空白の場所には透明な領域が表示されます。Falseの場合、ピクスマップのサンプルは 0xff で事前クリアされます。これにより、ページに表示する内容がない場所には white が表示されます。
Show/hide history
- v1.14.17で変更されました
デフォルトのalpha値は False になりました。
alpha=True で生成されたもの
alpha=False で生成されたもの
annots (bool) -- (v1.16.0で新たに追加) アノテーションをレンダリングするか抑制するか。注釈用に個別にピクスマップを作成できます。
- 戻り値の型:
- 戻り値:
ページのピクスマップ。生成されたイメージを細かく制御するために、最も重要なパラメータは matrix です。たとえば、Matrix(xzoom, yzoom)を使用してイメージの解像度を増減させることができます。zoom > 1の場合、より高い解像度が得られ、zoom=2はその方向のピクセル数を2倍にし、したがって2倍の大きさのイメージを生成します。非正の値は水平または垂直に反転させます。同様に、行列は回転やシアーも可能にし、行列の乗算を介して効果を組み合わせることもできます。詳細については、Matrix (マトリックス) セクションをご覧ください。
注釈
The pixmap will have "premultiplied" pixels if
alpha=True
. To learn about some background, e.g. look for "Premultiplied alpha" here.このメソッドはページの回転を尊重し、
clip
とPage.cropbox
の交差を超えません。ページのmediaboxが必要な場合(およびこれが異なる矩形の場合)、次のようなスニペットを使用してこれを実現できます:In [1]: import fitz In [2]: doc=fitz.open("demo1.pdf") In [3]: page=doc[0] In [4]: rotation = page.rotation In [5]: cropbox = page.cropbox In [6]: page.set_cropbox(page.mediabox) In [7]: page.set_rotation(0) In [8]: pix = page.get_pixmap() In [9]: page.set_cropbox(cropbox) In [10]: if rotation != 0: ...: page.set_rotation(rotation) ...: In [11]:
Show/hide history
v1.19.2で変更:dpiパラメータのサポートを追加。
- annot_names()#
PDFのみ:アノテーション、ウィジェット、およびリンクの名前のリストを返します。技術的には、これらはページの /Annots 配列で見つかるすべてのPDFオブジェクトの /NM 値です。
- 戻り値の型:
list
Show/hide history
新機能 v1.16.10
- annot_xrefs()#
PDFのみ:アノテーション、ウィジェット、およびリンクの
xref
番号のリストを返します。技術的には、これらはページの/Annots配列で見つかるすべてのエントリのxrefです。- 戻り値の型:
list
- 戻り値:
xref、タイプがアノテーションのタイプであるアイテム (xref, type) のリスト。リンク、フィールド、およびアノテーションを区別するためにタイプを使用します。アノテーションタイプ を参照してください。
Show/hide history
新機能 v1.17.1
- load_annot(ident)#
PDFのみ:ident で識別されるアノテーションを返します。これはその一意の名前(PDF
/NM
キー)またはxrefかもしれません。- パラメータ:
ident (str,int) -- アノテーションの名前またはxref。
- 戻り値の型:
- 戻り値:
アノテーションまたは None。
注釈
メソッド
Page.annot_names()
、Page.annot_xrefs()
は、アイテムが取得およびこのメソッドを介して読み込まれる名前またはxrefのリストを提供します。Show/hide history
新機能 v1.17.1
- load_widget(xref)#
PDFのみ:xref で識別されるフィールドを返します。
- パラメータ:
xref (int) -- フィールドのxref。
- 戻り値の型:
- 戻り値:
フィールドまたは None。
注釈
これはメソッド
Page.load_annot()
と同様ですが、ここでは識別子としてxrefのみがサポートされています。Show/hide history
新機能 v1.19.6
- load_links()#
最初のリンクを返します。プロパティ
first_link
の同義語です。- 戻り値の型:
- 戻り値:
ページ上の最初のリンク(または None)。
- set_rotation(rotate)#
PDFのみ:ページの回転を設定します。
- パラメータ:
rotate (int) -- 度数で指定された必要な回転を表す整数。90の整数倍である必要があります。値は0、90、180、270のいずれかに変換されます。
- remove_rotation()#
PDF only: Set page rotation to 0 while maintaining appearance and page content.
- 戻り値:
The inverted matrix used to achieve this change. If the page was not rotated (rotation 0), Identity (アイデンティティ) is returned. The method automatically recomputes the rectangles of any annotations, links and widgets present on the page.
This method may come in handy when e.g. used with
Page.show_pdf_page()
.
- show_pdf_page(rect, docsrc, pno=0, keep_proportion=True, overlay=True, oc=0, rotate=0, clip=None)#
PDFのみ:別のPDFのページをベクトルイメージとして表示します(それ以外は
Page.insert_image()
に類似)。これは多目的なメソッドです。たとえば、次のようなことに使用できます。既存のPDFファイルの「n-up」バージョンを作成し、複数の入力ページを1つの出力ページに結合します(例: combine.py を参照)。
「ポスター化」されたPDFファイルを作成します。つまり、各入力ページは別々の出力ページを作成する部分に分割されます(posterize.py を参照)。
企業のロゴ、透かし画像など、PDFベースのベクトル画像を含めます。svg-logo.py は、各ページにSVGベースのロゴを配置します(SVGからPDFへの変換を処理するために追加のパッケージが必要です)。
- パラメータ:
rect (rect_like) -- 現在のページに画像を配置する場所。有限である必要があり、ページとの交差部分が空でない必要があります。
docsrc (Document (ドキュメント)) -- ページを含むソースPDFドキュメント。異なるドキュメントオブジェクトである必要がありますが、同じファイルであることもあります。
pno (int) -- 表示するページ番号(0から始まる、
-∞ < pno < docsrc.page_count
)。指定されたページ。keep_proportion (bool) -- 幅高さ比率を維持するかどうか(デフォルト)。falseの場合、4つの角は常にターゲット矩形の境界に配置されます(回転値に関係なく)。一般的に、これは歪んだおよび/または非四角形の画像を提供します。
overlay (bool) -- 画像を前景(デフォルト)または背景に配置します。
oc (int) -- (
xref
) make visibility dependent on thisOCG
/OCMD
(which must be defined in the target PDF) [9]. (New in v1.18.3)rotate (float) -- show the source rectangle rotated by some angle. Any angle is supported (changed in v1.14.11). (New in v1.14.10)
clip (rect_like) -- 表示するソースページの一部を選択します。デフォルトはフルページですが、有限である必要があり、ソースページとの交差部分が空でない必要があります。
注釈
メソッド
Document.insert_pdf()
とは異なり、このメソッドは注釈、ウィジェット、リンクをコピーしないため、これらは対象に含まれません [6]。ただし、その他のすべてのリソース(テキスト、画像、フォントなど)は現在のPDFにインポートされます。したがって、テキストの抽出とget_fonts()
およびget_images()
リストに表示されます。表示領域に含まれていなくても。例:同じソースページを90度と-90度回転して表示します。
>>> doc = fitz.open() # new empty PDF >>> page=doc.new_page() # new page in A4 format >>> >>> # upper half page >>> r1 = fitz.Rect(0, 0, page.rect.width, page.rect.height/2) >>> >>> # lower half page >>> r2 = r1 + (0, page.rect.height/2, 0, page.rect.height/2) >>> >>> src = fitz.open("PyMuPDF.pdf") # show page 0 of this >>> >>> page.show_pdf_page(r1, src, 0, rotate=90) >>> page.show_pdf_page(r2, src, 0, rotate=-90) >>> doc.save("show.pdf")
Show/hide history
v1.14.11で変更:パラメータreuse_xrefは非推奨となりました。ソースの矩形をターゲットの矩形の中央に配置します。任意の回転角度がサポートされます。
v1.18.3で変更:新しいパラメータ
oc
が追加されました。
- new_shape()#
PDFのみ:ページ用の新しい Shape(シェイプ) オブジェクトを作成します。
- 戻り値の型:
- 戻り値:
複合描画に使用する新しい Shape(シェイプ) オブジェクト。詳細はそちらの説明を参照してください。
- search_for(needle, *, clip=None, quads=False, flags=TEXT_DEHYPHENATE | TEXT_PRESERVE_WHITESPACE | TEXT_PRESERVE_LIGATURES | TEXT_MEDIABOX_CLIP, textpage=None)#
ページ上で needle を検索します。
TextPage.search()
のラッパーです。- パラメータ:
needle (str) -- 検索対象のテキスト。スペースを含めることができます。大文字/小文字は無視されますが、ASCII文字に対してのみ機能します:たとえば、needleが「COMPÉTENCES」の場合、needleが「compétences」の場合には見つかりません。「compÉtences」の場合は見つかります。同様に、ドイツ語のウムラウトなどにも当てはまります。
clip (rect_like) -- only search within this area. (New in v1.18.2)
quads (bool) -- 四角形の代わりに Quad (クアッド) オブジェクトのタイプを返します。
flags (int) -- 基本となる TextPage (テキストページ) によって抽出されるデータを制御します。デフォルトでは、リガチャと空白を保持し、ハイフン化 [8] が検出されます。
textpage -- use a previously created TextPage (テキストページ). This reduces execution time significantly. If specified, the 'flags' and 'clip' arguments are ignored. If omitted, a temporary textpage will be created. (New in v1.19.0)
- 戻り値の型:
list
- 戻り値:
Rect (矩形) または Quad (クアッド) オブジェクトのリストで、通常、needleの一致を1つ囲みます。ただし、needleの一部が複数の行にまたがる場合、それぞれの部分に対して別のアイテムが生成されます。したがって、
needle = "search string"
の場合、2つの四角形が生成される可能性があります。Show/hide history
Changes in v1.18.2:
リストの長さに制限はもうありません(
hit_max
パラメータの削除)。単語が行の区切りでハイフン化されている場合でも、検出されます。たとえば、needleが行の区切りで「meth-od」としてハイフン化されていても、「method」としてハイフン化されていない部分を囲む1つの四角形と、「od」としてハイフン化されていない部分を囲む別の四角形が返されます。
注釈
このメソッドは、複数行のテキストマーカーアノテーションをサポートしており、返されたリスト全体を1つのパラメータとして使用してアノテーションを作成できます。
注意
トリッキーな側面があります。検索ロジックは、連続した複数の needle の出現を1つと見なします。つまり、needle が「abc」で、ページに「abc」と「abcabc」が含まれている場合、2つの矩形のみが返され、1つは「abc」に、もう1つは「abcabc」になります。
常に
Page.get_textbox()
を使用して、各矩形で実際に囲まれているテキストを確認できます。
注釈
"needle"
文字列を指定する際に正規表現をサポートする機能が何度も要求されていますが、これを行う方法はありません。この方向性の何かが必要な場合は、まず希望の形式でテキストを抽出し、それを正規表現パターンと一致させて結果をサブセレクトしてください。単語を一致させる例を以下に示します。>>> pattern = re.compile(r"...") # the regex pattern >>> words = page.get_text("words") # extract words on page >>> matches = [w for w in words if pattern.search(w[4])]
matches
リストには、指定されたパターンに一致する単語が含まれます。同様の方法で、page.get_text("dict")
の出力からspan["text"]
を選択できます。Show/hide history
v1.18.2で変更:
clip
パラメータを追加。hit_max
パラメータを削除。デフォルトの「デハイフェネート」を追加。v1.19.0で変更:TextPage (テキストページ) パラメータを追加。
- set_mediabox(r)#
PDFのみ: ページのオブジェクト定義内で
mediabox
を設定することにより、物理ページの寸法を変更します。- パラメータ:
r (rect-like) -- 新しい
mediabox
の値。
注釈
このメソッドは、ページの他の(オプションの)矩形(
cropbox
、ArtBox、TrimBox、Bleedbox)も削除し、一貫性のない状況を防ぐためにそれらをデフォルト値に戻します。注意
これにより、非空のページでは望ましくない効果が発生する可能性があるため、すべてのコンテンツの位置がこの値に依存し、したがって位置が変わるか、完全に消える可能性があります。
Show/hide history
v1.16.13で新規追加
v1.19.4で変更: 他のすべての矩形定義を削除しました。
- set_cropbox(r)#
PDFのみ: ページの表示領域を変更します。
- パラメータ:
r (rect_like) -- ページの新しい表示領域。これは回転していない座標で指定する必要があり、空ではなく、無限ではなく、
Page.mediabox
に完全に含まれている必要があります。
実行後(ページが回転していない場合)、
Page.rect
はこの矩形と等しくなりますが、必要に応じて左上の位置(0、0)にシフトされます。以下は例セッションです:>>> page = doc.new_page() >>> page.rect fitz.Rect(0.0, 0.0, 595.0, 842.0) >>> >>> page.cropbox # cropbox and mediabox still equal fitz.Rect(0.0, 0.0, 595.0, 842.0) >>> >>> # now set cropbox to a part of the page >>> page.set_cropbox(fitz.Rect(100, 100, 400, 400)) >>> # this will also change the "rect" property: >>> page.rect fitz.Rect(0.0, 0.0, 300.0, 300.0) >>> >>> # but mediabox remains unaffected >>> page.mediabox fitz.Rect(0.0, 0.0, 595.0, 842.0) >>> >>> # revert CropBox change >>> # either set it to MediaBox >>> page.set_cropbox(page.mediabox) >>> # or 'refresh' MediaBox: will remove all other rectangles >>> page.set_mediabox(page.mediabox)
- set_artbox(r)#
- set_bleedbox(r)#
- set_trimbox(r)#
PDFのみ: ページオブジェクト内の対応する矩形を設定します。これらのオブジェクトの意味については、Adobe PDFリファレンス の77ページを参照してください。パラメータと制約は
Page.set_cropbox()
と同じです。Show/hide history
v1.19.4で新規追加
- rotation#
Contains the rotation of the page in degrees (always 0 for non-PDF types). This is a copy of the value in the PDF file. The PDF documentation says:
"The number of degrees by which the page should be rotated clockwise when displayed or printed. The value must be a multiple of 90. Default value: 0."
In PyMuPDF, we make sure that this attribute is always one of 0, 90, 180 or 270.
- Type:
int
- cropbox_position#
PDFの場合、ページの
/CropBox
の左上の点を含みます。それ以外の場合は Point(0, 0)。- Type:
- cropbox#
PDFのページの
/CropBox
です。常に 回転していない ページの矩形が返されます。非PDFの場合、これは常にページの矩形と等しいです。注釈
PDFでは、
/MediaBox
、/CropBox
、およびページの矩形の関係は混乱することがあります。MediaBox
の用語集を参照してください。- Type:
- artbox#
- bleedbox#
- trimbox#
PDFのページの/ArtBox、/BleedBox、/TrimBoxです。指定されていない場合、
Page.cropbox
にデフォルトで設定されます。- Type:
- mediabox_size#
PDFのページの
Page.mediabox
の幅と高さを含みます。それ以外の場合、Page.rect
の右下の座標です。- Type:
- mediabox#
PDFのページの
mediabox
、それ以外の場合はPage.rect
です。- Type:
注釈
ほとんどのPDF文書および他のすべてのドキュメントタイプに対して、
page.rect == page.cropbox == page.mediabox
が真です。ただし、一部のPDFでは、表示ページが v の真の部分集合である場合があります。また、ページが回転している場合、Page.rect
はPage.cropbox
と等しくないかもしれません。これらの場合、上記の属性はページの要素を正しく位置付けるのに役立ちます。
- transformation_matrix#
この行列は、PDF空間からMuPDF空間への座標の変換に使用されます。たとえば、PDFの
/Rect [x0 y0 x1 y1]
では、ペア(x0、y0)が矩形の左下の点を指定します。これはMuPDFのシステムとは異なり、ここでは(x0、y0)は左上を指定します。PDF座標をこの行列で掛け算すると、(Py-)MuPDF矩形バージョンが得られます。明らかに、逆行列は再びPDF矩形を返します。- Type:
- rotation_matrix#
- derotation_matrix#
これらの行列は、回転したPDFページの取り扱いに使用できます。PDFページに何かを追加/挿入する際、回転していない ページの座標が常に使用されます。これらの行列は、2つの状態間での変換を支援します。例:ページが90度回転した場合、A4ページの左上のPoint(0, 0)の座標は何になりますか?
>>> page.set_rotation(90) # rotate an ISO A4 page >>> page.rect Rect(0.0, 0.0, 842.0, 595.0) >>> p = fitz.Point(0, 0) # where did top-left point land? >>> p * page.rotation_matrix Point(842.0, 0.0) >>>
- Type:
- first_link#
ページの最初の Link (リンク) を含みます(または None)。
- Type:
- first_annot#
ページの最初の Annot (注釈) を含みます(または None)。
- Type:
- first_widget#
ページの最初の Widget (ウィジェット) を含みます(または None)。
- Type:
- number#
ページ番号。
- Type:
int
- parent#
所属するドキュメントオブジェクト。
- Type:
- rect#
ページの矩形を含みます。
Page.bound()
の結果と同じです。- Type:
get_links() エントリの説明#
Page.get_links()
リストの各エントリは、以下のキーを持つ辞書です:
kind:(必須)リンクの種類を示す整数。LINK_NONE、LINK_GOTO、LINK_GOTOR、LINK_LAUNCH、または LINK_URI のいずれかです。
from:(必須)ページの可視な表現上の「ホットスポット」の場所を示す Rect (矩形) (通常、カーソルが手のイメージに変わる場所です)。
page:宛先ページを示す0ベースの整数。LINK_GOTO*および *LINK_GOTOR の場合に必要ですが、それ以外の場合は無視されます。
to:宛先ページ上の宛先場所を指定する fitz.Point、デフォルトは fitz.Point(0, 0)、またはシンボリック(間接)名です。間接名が指定された場合、page = -1 が必要で、名前はPDFで定義されている必要があります。LINK_GOTO および LINK_GOTOR の場合に必要ですが、それ以外の場合は無視されます。
file:宛先ファイルを指定する文字列。LINK_GOTORおよびLINK_LAUNCHの場合に必要ですが、それ以外の場合は無視されます。
uri: LINK_URI用に指定された、インターネットリソースの宛先を示す文字列。LINK_URI の場合に必要で、それ以外の場合は無視されます。この文字列は、
"http://"
、"https://"
、"file://"
、"ftp://"
、"mailto:"
など、URLのサブタイプを識別する明確なサブストリングで始めるようにしてください。そうしないと、ブラウザがテキストを解釈し、意図しない/予期しない結論に達する可能性があります。xref: an integer specifying the PDF
xref
of the link object. Do not change this entry in any way. Required for link deletion and update, otherwise ignored. For non-PDF documents, this entry contains -1. It is also -1 for all entries in the get_links() list, if any of the links is not supported by MuPDF - see リンクのサポートに関する注記.
リンクのサポートに関する注記#
v1.10a 以降、MuPDFのリンクサポートが変更されました。これらの変更は LINK_GOTO
および LINK_GOTOR
というリンクタイプに影響を与えます。
読み取り get_links() メソッドおよび*first_link* プロパティチェーンに関連)#
MuPDFが別のファイルへのリンクを検出する場合、LINK_GOTOR または LINK_LAUNCH リンクの種類を提供します。LINK_GOTOR の場合、宛先の詳細はページ番号(位置情報を含むことがある)または間接的な宛先として指定できます。
間接的な宛先が指定された場合、page = -1で示され、link.dest.dest にこの名前が含まれます。 get_links() リスト内の辞書には、この情報がto値として含まれます。
内部リンクは常にLINK_GOTOの種類です。内部リンクが間接的な宛先を指定した場合、常に解決され、結果の直接的な宛先が返されます。内部リンクには名前は返されず、未定義の宛先はリンクが無視される原因になります。
書き込み#
PyMuPDFはリンクを構築して適切なPDFオブジェクト ソース を書き込むことにより、リンクを書き込み(更新、挿入)します。これにより、 LINK_GOTOR および LINK_GOTO リンク種別に対して間接的な宛先を指定できます(PDF 1.2 ファイル形式以前はサポートされていません)。
警告
LINK_GOTO の間接的な宛先が未定義の名前を指定した場合、このリンクは後でMuPDF / PyMuPDFで再び見つけることはできません。ただし、他のリーダーはそれを検出し、エラーとしてフラグ付けます。
一般的な注意: 間接的な LINK_GOTOR の宛先は一般的に有効性を確認できないため、常に受け入れられます。
例: 同じドキュメント内の別のページを指すリンクを挿入する方法
リンクを配置する現在のページの矩形を決定します。これは画像または一部のテキストのbboxである場合があります。
ターゲットページ番号(0から始まる)と、リンクを指定するためのそのページ上の Point (ポイント) を決定します。
辞書d = {"kind": fitz.LINK_GOTO, "page": pno, "from": bbox, "to": point}を作成します。
page.insert_link(d)を実行します。
Document (ドキュメント) と Page (ページ) の同様のメソッドに関する説明です。#
これは、Document (ドキュメント) と Page (ページ) レベルでの同様のメソッドの概要です。
Document Level(ドキュメントレベル) |
Page Level(ページレベル) |
---|---|
Document.get_page_fonts(pno) |
|
Document.get_page_images(pno) |
|
Document.get_page_pixmap(pno, ...) |
|
Document.get_page_text(pno, ...) |
|
Document.search_page_for(pno, ...) |
ページ番号「pno」は0から始まる整数であり、-∞ < pno < page_count
です。
注釈
多くのドキュメントメソッド(左側の列)は利便性のために存在し、Document[pno].<page method> のラッパーであるだけで、各実行でページを読み込んで破棄します。
ただし、最初の2つのメソッドは異なる方法で動作します。これらはページのオブジェクト定義ステートメントだけを必要とし、ページ自体は読み込まれません。例えば、Page.get_fonts()
は逆に定義され、次のようになります: page.get_fonts == page.parent.get_page_fonts(page.number)。
脚注