PyMuPDF Pro¶
PyMuPDF Pro は、PyMuPDF 用の 商用拡張機能 セットです。
Office ドキュメントサポートと RAG/LLM 統合で PyMuPDF の機能を強化します。
doc、docx、hwp、hwpx、ppt、pptx、xls、xlsxなどの Office ドキュメント処理を可能にします。テキストと表の抽出、ドキュメント変換などをサポートします。
PyMuPDF4LLM の商用バージョンが含まれています。
To enquire about obtaining a commercial license, then use this contact page.
Trial license keys are available for evaluation purposes. Please fill out the form on this page to obtain a trial key.
注釈
PyMuPDF Pro のライセンス版には、PyMuPDF4LLM のライセンス版も含まれています。PyMuPDF4LLM パッケージの使用に興味がある場合は、個別にインストールする必要があります。
プラットフォームサポート¶
以下のプラットフォームでのみ利用可能
Windows x86_64.
Linux x86_64 (glibc).
MacOS x86_64.
MacOS arm64.
Office ファイルサポート¶
PyMuPDF がサポートする標準ファイルタイプ に加えて、PyMuPDF Pro は以下をサポートします
使用方法¶
インストール¶
pip でインストールするには
pip install pymupdfpro
Office ドキュメントを読み込む¶
PyMuPDF Pro をインポートすると、Office ドキュメントを直接参照できます。例えば:
import pymupdf.pro
pymupdf.pro.unlock()
# PyMuPDF has now been extended with PyMuPDF Pro features, with some restrictions.
doc = pymupdf.open("my-office-doc.xls")
注釈
すべての標準 PyMuPDF 機能が期待どおりに公開されます - PyMuPDF Pro は拡張された Office ファイルタイプを処理します
その後は、制限事項 を考慮しながら、通常どおりドキュメントページを操作できます。
制限事項¶
PyMuPDF Pro 機能は、ライセンスキーがない場合、次のように制限されます:
どのドキュメントでも最初の3ページのみが利用可能です。
To unlock full functionality you should obtain a trial key.
トライアルキー¶
To obtain a license key please fill out the form on this page. You will then have the trial key emailled to the address you submitted.
キーの使用¶
次のようにキーで PyMuPDF Pro を初期化します
import pymupdf.pro
pymupdf.pro.unlock(my_key)
# PyMuPDF has now been extended with PyMuPDF Pro features.
This will allow you to evaluate the product for a limited time. If you want to use PyMuPDF Pro after this time you should then enquire about obtaining a commercial license.
Converting¶
Office document to PDF¶
Use the office_to_pdf() method to convert an Office document to PDF, e.g.:
import pymupdf.pro
pymupdf.pro.unlock()
pymupdf.pro.office_to_pdf("input.docx", "output.pdf")
If you require a byte representation of the PDF data, you can use the office_to_pdf() without specifying an output file, e.g.:
import pymupdf.pro
pymupdf.pro.unlock()
pdfdata = pymupdf.pro.office_to_pdf("input.docx")
Office document to Images¶
In order to convert an Office document to images, you should iterate the document pages, convert to Pixmap and save, e.g.:
doc = pymupdf.open("input.docx")
for i, page in enumerate(doc):
pix = page.get_pixmap(dpi=200)
pix.save(f"page-{i+1}.png")
doc.close()
Office document to Markdown¶
Use the office_to_markdown() method to convert an Office document to Markdown, e.g.:
import pymupdf.pro
pymupdf.pro.unlock()
pymupdf.pro.office_to_markdown("input.docx", "output.md")
If you require a string representation of the Markdown data, you can use the office_to_markdown() without specifying an output file.
Office document to JSON¶
Use the office_to_json() method to convert an Office document to JSON, e.g.:
import pymupdf.pro
pymupdf.pro.unlock()
pymupdf.pro.office_to_json("input.docx", "output.json")
If you require a string representation of the JSON data, you can use the office_to_json() without specifying an output file.
フォント¶
デフォルトでは、pymupdf.pro.unlock() はインストールされているすべてのフォントディレクトリを検索します。
これは、キーワード専用引数で制御できます:
fontpath: 特定のフォントディレクトリ。リスト/タプルまたはos.sepで区切られた文字列として指定します。None(デフォルト)の場合、設定されていればos.environ['PYMUPDFPRO_FONT_PATH']を使用します。fontpath_auto: システムフォントディレクトリを追加するかどうか。None(デフォルト)の場合、os.environ['PYMUPDFPRO_FONT_PATH_AUTO']が '1' であれば true を使用します。true の場合、すべてのシステムフォントディレクトリを追加します。
関数 pymupdf.pro.get_fontpath() は、unlock() で使用されるすべてのフォントディレクトリのタプルを返します。
API¶
- office_to_pdf(input_path: str, output_path: str = None) bytes | None¶
Reads the input file and converts its contents into PDF format.
- パラメータ:
input_path (str) -- the input file path.
output_path (str) -- the path to the output file. If
None, the method returns the bytes of the PDF content.
- 戻り値:
Either bytes of the PDF content,
Noneifoutput_pathis specified.
- office_to_markdown(input_path: str, output_path: str = None) str | None¶
Reads the input file and outputs the text of its pages in Markdown format.
- パラメータ:
input_path (str) -- the input file path.
output_path (str) -- the path to the output file. If
None, the method returns the content as a string.
- 戻り値:
Either a string of the Markdown representation,
Noneifoutput_pathis specified.
- office_to_json(input_path: str, output_path: str = None) str | None¶
Reads the input file and outputs the text of its pages in JSON format.
- パラメータ:
input_path (str) -- the input file path.
output_path (str) -- the path to the output file. If
None, the method returns the content as a string.
- 戻り値:
Either a string of the JSON representation,
Noneifoutput_pathis specified.
