Communityコーディング&開発github.com

PDF

包括的なPDF操作ツールキット。テキスト抽出、テーブル抽出、新しいPDFの作成、ドキュメントの結合・分割、フォーム処理をサポートします。ClaudeがPDFフォームへの入力や、プログラムによるPDFドキュメントの処理、生成、分析を大規模に行う必要がある場合に使用します。

PDF とは?

このスキルは、Pythonライブラリ(pypdf、pdfplumber、reportlab)とコマンドラインツール(pdftotext、qpdf、pdftk)を活用した包括的なPDF処理ガイドです。テキストやテーブルの抽出、PDFの結合・分割、メタデータ抽出、ページ回転、透かし追加、パスワード保護、OCRによるスキャンPDFからのテキスト抽出、画像抽出など、幅広い操作をカバーしています。特に、大量のPDFドキュメントをプログラムで処理する必要がある開発者や、Claude CodeのようなAIエージェントがドキュメント操作タスクを自動化するために設計されています。プラットフォームはPythonおよび一般的なコマンドライン環境に対応しており、各操作の具体的なコード例やコマンドが豊富に提供されているため、実装が容易です。また、高度な機能やPDFフォームの入力については別のドキュメント(reference.md、forms.md)を参照するよう指示しています。

対応✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComposioHQ/awesome-claude-skills/tree/master/document-skills/pdf

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

PDF 処理ガイド

概要

このガイドでは、Pythonライブラリとコマンドラインツールを使用した基本的なPDF処理操作について説明します。高度な機能、JavaScriptライブラリ、および詳細な例については、reference.mdを参照してください。PDFフォームに記入する必要がある場合は、forms.mdを読み、その指示に従ってください。

クイックスタート

from pypdf import PdfReader, PdfWriter

# PDFを読み込む
reader = PdfReader("document.pdf")
print(f"ページ数: {len(reader.pages)}")

# テキストを抽出
text = ""
for page in reader.pages:
    text += page.extract_text()

Pythonライブラリ

pypdf - 基本操作

PDFの結合

from pypdf import PdfWriter, PdfReader

writer = PdfWriter()
for pdf_file in ["doc1.pdf", "doc2.pdf", "doc3.pdf"]:
    reader = PdfReader(pdf_file)
    for page in reader.pages:
        writer.add_page(page)

with open("merged.pdf", "wb") as output:
    writer.write(output)

PDFの分割

reader = PdfReader("input.pdf")
for i, page in enumerate(reader.pages):
    writer = PdfWriter()
    writer.add_page(page)
    with open(f"page_{i+1}.pdf", "wb") as output:
        writer.write(output)

メタデータの抽出

reader = PdfReader("document.pdf")
meta = reader.metadata
print(f"タイトル: {meta.title}")
print(f"作成者: {meta.author}")
print(f"件名: {meta.subject}")
print(f"作成アプリ: {meta.creator}")

ページの回転

reader = PdfReader("input.pdf")
writer = PdfWriter()

page = reader.pages[0]
page.rotate(90)  # 90度時計回りに回転
writer.add_page(page)

with open("rotated.pdf", "wb") as output:
    writer.write(output)

pdfplumber - テキストとテーブルの抽出

レイアウトを保持したテキスト抽出

import pdfplumber

with pdfplumber.open("document.pdf") as pdf:
    for page in pdf.pages:
        text = page.extract_text()
        print(text)

テーブルの抽出

with pdfplumber.open("document.pdf") as pdf:
    for i, page in enumerate(pdf.pages):
        tables = page.extract_tables()
        for j, table in enumerate(tables):
            print(f"ページ {i+1} のテーブル {j+1}:")
            for row in table:
                print(row)

高度なテーブル抽出

import pandas as pd

with pdfplumber.open("document.pdf") as pdf:
    all_tables = []
    for page in pdf.pages:
        tables = page.extract_tables()
        for table in tables:
            if table:  # テーブルが空でないか確認
                df = pd.DataFrame(table[1:], columns=table[0])
                all_tables.append(df)

# すべてのテーブルを結合
if all_tables:
    combined_df = pd.concat(all_tables, ignore_index=True)
    combined_df.to_excel("extracted_tables.xlsx", index=False)

reportlab - PDFの作成

基本的なPDF作成

from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

c = canvas.Canvas("hello.pdf", pagesize=letter)
width, height = letter

# テキストを追加
c.drawString(100, height - 100, "Hello World!")
c.drawString(100, height - 120, "This is a PDF created with reportlab")

# 線を追加
c.line(100, height - 140, 400, height - 140)

# 保存
c.save()

複数ページのPDF作成

from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageBreak
from reportlab.lib.styles import getSampleStyleSheet

doc = SimpleDocTemplate("report.pdf", pagesize=letter)
styles = getSampleStyleSheet()
story = []

# コンテンツを追加
title = Paragraph("レポートタイトル", styles['Title'])
story.append(title)
story.append(Spacer(1, 12))

body = Paragraph("これはレポートの本文です。" * 20, styles['Normal'])
story.append(body)
story.append(PageBreak())

# 2ページ目
story.append(Paragraph("2ページ目", styles['Heading1']))
story.append(Paragraph("2ページ目のコンテンツ", styles['Normal']))

# PDFを生成
doc.build(story)

コマンドラインツール

pdftotext (poppler-utils)

# テキストを抽出
pdftotext input.pdf output.txt

# レイアウトを保持してテキストを抽出
pdftotext -layout input.pdf output.txt

# 特定のページを抽出
pdftotext -f 1 -l 5 input.pdf output.txt  # 1~5ページ

qpdf

# PDFを結合
qpdf --empty --pages file1.pdf file2.pdf -- merged.pdf

# ページを分割
qpdf input.pdf --pages . 1-5 -- pages1-5.pdf
qpdf input.pdf --pages . 6-10 -- pages6-10.pdf

# ページを回転
qpdf input.pdf output.pdf --rotate=+90:1  # 1ページ目を90度回転

# パスワードを解除
qpdf --password=mypassword --decrypt encrypted.pdf decrypted.pdf

pdftk (利用可能な場合)

# 結合
pdftk file1.pdf file2.pdf cat output merged.pdf

# 分割
pdftk input.pdf burst

# 回転
pdftk input.pdf rotate 1east output rotated.pdf

一般的なタスク

スキャンPDFからのテキスト抽出

# 必要: pip install pytesseract pdf2image
import pytesseract
from pdf2image import convert_from_path

# PDFを画像に変換
images = convert_from_path('scanned.pdf')

# 各ページをOCR処理
text = ""
for i, image in enumerate(images):
    text += f"ページ {i+1}:\n"
    text += pytesseract.image_to_string(image)
    text += "\n\n"

print(text)

透かしの追加

from pypdf import PdfReader, PdfWriter

# 透かしを作成(または既存のものを読み込み)
watermark = PdfReader("watermark.pdf").pages[0]

# 全ページに適用
reader = PdfReader("document.pdf")
writer = PdfWriter()

for page in reader.pages:
    page.merge_page(watermark)
    writer.add_page(page)

with open("watermarked.pdf", "wb") as output:
    writer.write(output)

画像の抽出

# pdfimages を使用(poppler-utils)
pdfimages -j input.pdf output_prefix

# これにより、すべての画像が output_prefix-000.jpg、output_prefix-001.jpg などとして抽出されます。

パスワード保護

from pypdf import PdfReader, PdfWriter

reader = PdfReader("input.pdf")
writer = PdfWriter()

for page in reader.pages:
    writer.add_page(page)

# パスワードを追加
writer.encrypt("userpassword", "ownerpassword")

with open("encrypted.pdf", "wb") as output:
    writer.write(output)

クイックリファレンス

タスク最適なツールコマンド/コード
PDFの結合pypdfwriter.add_page(page)
PDFの分割pypdfファイルごとに1ページ
テキスト抽出pdfplumberpage.extract_text()
テーブル抽出pdfplumberpage.extract_tables()
PDFの作成reportlabCanvasまたはPlatypus
コマンドライン結合qpdfqpdf --empty --pages ...
スキャンPDFのOCRpytesseractまず画像に変換
PDFフォームの入力pdf-lib または pypdf(forms.md参照)forms.mdを参照

次のステップ

  • 高度なpypdfium2の使用法については、reference.mdを参照してください
  • JavaScriptライブラリ(pdf-lib)については、reference.mdを参照してください
  • PDFフォームに記入する必要がある場合は、forms.mdの指示に従ってください
  • トラブルシューティングガイドについては、reference.mdを参照してください

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ably-automation

Automate Ably tasks via Rube MCP (Composio). Always search tools first for current schemas.

abstract-automation

Automate Abstract tasks via Rube MCP (Composio). Always search tools first for current schemas.

abuselpdb-automation

Automate Abuselpdb tasks via Rube MCP (Composio). Always search tools first for current schemas.

abyssale-automation

Automate Abyssale tasks via Rube MCP (Composio). Always search tools first for current schemas.

accelo-automation

Automate Accelo tasks via Rube MCP (Composio). Always search tools first for current schemas.

accredible-certificates-automation

Automate Accredible Certificates tasks via Rube MCP (Composio). Always search tools first for current schemas.

acculynx-automation

Automate Acculynx tasks via Rube MCP (Composio). Always search tools first for current schemas.

active-campaign-automation

Automate ActiveCampaign tasks via Rube MCP (Composio). Always search tools first for current schemas.

addresszen-automation

Automate Addresszen tasks via Rube MCP (Composio). Always search tools first for current schemas.

adobe-automation

Automate Adobe tasks via Rube MCP (Composio). Always search tools first for current schemas.

adrapid-automation

Automate Adrapid tasks via Rube MCP (Composio). Always search tools first for current schemas.

adyntel-automation

Automate Adyntel tasks via Rube MCP (Composio). Always search tools first for current schemas.

aeroleads-automation

Automate Aeroleads tasks via Rube MCP (Composio). Always search tools first for current schemas.

aero-workflow-automation

Automate Aero Workflow tasks via Rube MCP (Composio). Always search tools first for current schemas.

affinda-automation

Automate Affinda tasks via Rube MCP (Composio). Always search tools first for current schemas.

affinity-automation

Automate Affinity tasks via Rube MCP (Composio). Always search tools first for current schemas.

agencyzoom-automation

Automate Agencyzoom tasks via Rube MCP (Composio). Always search tools first for current schemas.

agent-mail-automation

Automate Agent Mail tasks via Rube MCP (Composio). Always search tools first for current schemas.

agentql-automation

Automate Agentql tasks via Rube MCP (Composio). Always search tools first for current schemas.

agenty-automation

Automate Agenty tasks via Rube MCP (Composio). Always search tools first for current schemas.

関連スキル