mcpField
T
table-extractor

table-extractor

github.com/dkyazzentwatwaドキュメント125122 回インストール29 週間前に更新
リポジトリ

table-extractor について

table-extractorは、PDFや画像から表を抽出し、構造化データに変換するPythonツールです。スキャン資料のOCRや複数ページの処理、各種形式への出力に対応しています。

主な機能

  1. 01PDF・画像からの表抽出
  2. 02スキャン画像のOCR抽出
  3. 03複数ページの処理
  4. 04CSV、Excel、JSONへの出力
  5. 05表の境界と列の検出

活用シーン

  1. 01PDFレポートからの表抽出
  2. 02スキャン帳票の構造化データ化
  3. 03指定ページ範囲のPDF処理

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/dkyazzentwatwa/chatgpt-skills --skill table-extractor

インストール後、Claude Code で/table-extractorを入力して読み込まれたか確認します。

同梱ファイルscripts/requirements.txtscripts/table_extractor.py

詳細

表抽出ツール

PDF や画像から表を抽出し、構造化データ形式に変換します。

機能

  • PDF の表:デジタル PDF から表を抽出します
  • 画像の表:画像から OCR ベースで抽出します
  • 複数の表:ドキュメント内のすべての表を抽出します
  • 形式のエクスポート:CSV、Excel、JSON 形式で出力します
  • 表の検出:表の境界を自動検出します
  • 列の配置:列をスマートに検出します
  • 複数ページ:PDF ドキュメント全体を処理します

クイックスタート

from table_extractor import TableExtractor

extractor = TableExtractor()

# Extract from PDF
extractor.load_pdf("document.pdf")
tables = extractor.extract_all()

# Save first table to CSV
tables[0].to_csv("table.csv")

# Extract from image
extractor.load_image("scanned_table.png")
table = extractor.extract_table()
print(table)

CLI の使用方法

# Extract from PDF
python table_extractor.py --input document.pdf --output tables/

# Extract specific pages
python table_extractor.py --input document.pdf --pages 1-3 --output tables/

# Extract from image
python table_extractor.py --input scan.png --output table.csv

# Export to Excel
python table_extractor.py --input document.pdf --format xlsx --output tables.xlsx

# With OCR for scanned PDFs
python table_extractor.py --input scanned.pdf --ocr --output tables/

API リファレンス

TableExtractor クラス
class TableExtractor:
    def __init__(self)

    # Loading
    def load_pdf(self, filepath: str, pages: List[int] = None) -> 'TableExtractor'
    def load_image(self, filepath: str) -> 'TableExtractor'

    # Extraction
    def extract_table(self, page: int = 0) -> pd.DataFrame
    def extract_all(self) -> List[pd.DataFrame]
    def extract_page(self, page: int) -> List[pd.DataFrame]

    # Detection
    def detect_tables(self, page: int = 0) -> List[Dict]
    def get_table_count(self) -> int

    # Configuration
    def set_ocr(self, enabled: bool = True, lang: str = "eng") -> 'TableExtractor'
    def set_column_detection(self, mode: str = "auto") -> 'TableExtractor'

    # Export
    def to_csv(self, tables: List, output_dir: str) -> List[str]
    def to_excel(self, tables: List, output: str) -> str
    def to_json(self, tables: List, output: str) -> str

対応形式

入力
  • PDF ドキュメント(テキストベースおよびスキャン済み)
  • 画像:PNG、JPEG、TIFF、BMP
  • 表を含むスクリーンショット
出力
  • CSV(表ごとに 1 ファイル)
  • Excel(複数のシート)
  • JSON(表の配列)
  • Pandas DataFrame

表の検出

# Detect tables without extracting
tables_info = extractor.detect_tables(page=0)
# Returns:
# [
#     {"index": 0, "rows": 10, "cols": 5, "bbox": (x1, y1, x2, y2)},
#     {"index": 1, "rows": 8, "cols": 3, "bbox": (x1, y1, x2, y2)}
# ]

ワークフローの例

PDF レポートの表
extractor = TableExtractor()
extractor.load_pdf("quarterly_report.pdf")

# Extract all tables
tables = extractor.extract_all()

# Export each to CSV
for i, table in enumerate(tables):
    table.to_csv(f"table_{i}.csv", index=False)
スキャン済みドキュメント
extractor = TableExtractor()
extractor.set_ocr(enabled=True, lang="eng")
extractor.load_image("scanned_form.png")

table = extractor.extract_table()
print(table)

依存関係

  • pdfplumber>=0.10.0
  • pillow>=10.0.0
  • pandas>=2.0.0
  • pytesseract>=0.3.10(OCR 用)
  • opencv-python>=4.8.0

コメント