pdf-extractor
PDFファイルからテキストやフォームデータを抽出・分析します。
When & Why to Use This Skill
The PDF Extractor skill empowers Claude to seamlessly extract text, form fields, and metadata from PDF documents. It transforms unstructured PDF files into structured JSON data, facilitating automated data processing, deep document analysis, and efficient information retrieval for various business and research workflows.
Use Cases
- Automated Data Entry: Extracting specific field values from PDF application forms, invoices, or surveys to populate databases or spreadsheets.
- Content Summarization: Retrieving full-text content from lengthy reports, research papers, or legal documents to generate concise summaries.
- Metadata Management: Accessing document properties such as author, creation date, and page count to organize and categorize large digital libraries.
- Information Analysis: Converting PDF-based tables and structured text into machine-readable formats for further data analysis and insight generation.
| name | pdf-extractor |
|---|---|
| description | PDFファイルからテキストやフォームデータを抽出・分析します。 |
| meta | true |
PDF Extractor Skill
このスキルはPDFファイルから情報を抽出し、構造化データとして返します。
機能
- テキスト抽出: PDFの全テキストを抽出
- フォーム解析: PDFフォームのフィールドと値を抽出
- メタデータ取得: 作成者、作成日、ページ数などのメタ情報
使用方法
基本的な使い方
Input: "docs/report.pdf"
Output: 抽出されたテキストとメタデータをJSON形式で返却
実装アプローチ
Rubyを使用する場合:
# Gemfile に追加 gem 'pdf-reader' # 使用例 require 'pdf-reader' reader = PDF::Reader.new('path/to/file.pdf') reader.pages.each { |page| puts page.text }コマンドラインツールを使用する場合:
# pdftotext (poppler-utils) pdftotext input.pdf output.txt # pdftk でフォームデータ抽出 pdftk input.pdf dump_data_fields
出力形式
{
"file": "docs/report.pdf",
"pages": 10,
"text": "抽出されたテキスト全文",
"metadata": {
"author": "作成者名",
"created_at": "2024-01-01",
"title": "ドキュメントタイトル"
},
"fields": [
{
"name": "field_name",
"value": "field_value",
"type": "text"
}
]
}
使用例
例1: ドキュメントからテキスト抽出
User: Extract text from docs/requirements.pdf
Agent: [PDF extractorスキルを使用してテキストを抽出]
例2: フォームデータの解析
User: Parse form data from docs/application_form.pdf
Agent: [フォームフィールドと値を抽出してJSON形式で返却]
サンプルスクリプト
#!/usr/bin/env ruby
# scripts/extract_pdf.rb
require 'pdf-reader'
require 'json'
def extract_pdf(file_path)
reader = PDF::Reader.new(file_path)
data = {
file: file_path,
pages: reader.page_count,
text: '',
metadata: {
title: reader.info[:Title],
author: reader.info[:Author],
created_at: reader.info[:CreationDate]
}
}
reader.pages.each do |page|
data[:text] += page.text + "\n"
end
puts JSON.pretty_generate(data)
end
if __FILE__ == $0
extract_pdf(ARGV[0])
end
インストール要件
Ruby Gem
cd back
bundle add pdf-reader
システムツール(オプション)
# macOS
brew install poppler
# Ubuntu/Debian
apt-get install poppler-utils
注意事項
- meta: true: スキルの内部実装は隠蔽され、使用方法のみが公開されます
- 読み取り専用: PDFファイルの変更は行いません
- エンコーディング: 日本語PDFの場合、エンコーディングに注意が必要
- セキュリティ: アップロードされたPDFを処理する場合は、ファイルサイズとコンテンツの検証を行う