This project, named mistral-ocr-pdf2markdown
, converts PDF documents into Markdown format by leveraging the Mistral OCR API. It extracts text and images from PDFs and generates a Markdown file with inline images. This tool requires a valid Mistral API key and Python 3 to run.
- Python 3
- mistralai
- python-dotenv
Install the required packages:
pip install mistralai python-dotenv
-
Clone the repository or place the files
Ensure the following directory structure:
├── ocr.py ├── README.md └── .env
-
Environment Variable Setup
Create a
.env
file in the project root with the following content:MISTRAL_API_KEY=your_actual_api_key_here
Alternatively, you can set the environment variable directly.
Run the script from the terminal:
python ocr.py --pdf /path/to/your/file.pdf --output /path/to/output_directory
--pdf
: Path to the PDF file to process--output
: Base directory for output files
├── ocr.py # Main script for OCR processing
├── README.md # This README file
└── .env # Environment variable file (contains MISTRAL_API_KEY)
This project is licensed under the MIT License. Please adhere to the license terms of the dependent libraries and the Mistral OCR API.
This tool uses the Mistral OCR API. Be aware of any rate limits or billing constraints associated with the API. For more details, see the Mistral API documentation.
このプロジェクト(mistral-ocr-pdf2markdown
)は、Mistral OCR API を活用して PDF 文書を Markdown 形式に変換するツールです。PDFからテキストや画像を抽出し、インライン画像付きのMarkdownファイルを生成します。
Mistral OCR APIを使ってPDFをMarkdownファイルに変換してみた!(画像埋め込み対応🚀)
- Python 3
- mistralai
- python-dotenv
以下のコマンドで必要なパッケージをインストールします:
pip install mistralai python-dotenv
-
リポジトリのクローンまたはファイルの配置
下記のようなディレクトリ構成にしてください(例):
├── ocr.py ├── README.md └── .env
-
環境変数の設定
プロジェクトのルートディレクトリに
.env
ファイルを作成し、以下の内容を記述してください:MISTRAL_API_KEY=your_actual_api_key_here
もしくは、環境変数を直接設定してください。
ターミナルでスクリプトがあるディレクトリに移動し、以下のように実行します:
python ocr.py --pdf /path/to/your/file.pdf --output /path/to/output_directory
--pdf
: 処理するPDFファイルのパス--output
: 出力ファイルの基底ディレクトリ
├── ocr.py # OCR処理を行うメインスクリプト
├── README.md # このREADMEファイル
└── .env # 環境変数ファイル(MISTRAL_API_KEY を含む)
このプロジェクトはMITライセンスの下で公開されています。依存しているライブラリやMistral OCR APIの利用規約にも準拠してください。
本ツールはMistral OCR APIを利用しています。APIの利用にあたっては、レートリミットや課金などの制約がある場合があります。詳細はMistral APIドキュメントをご確認ください。