Communitygithub.com

Anhvu1107/all-agent-skill

PDFファイルの読み取り、抽出、分割、結合、回転、作成、検証、OCR、フォーム入力、その他の生成や変更に関するタスクでは、常にこれを使用します。

all-agent-skill とは?

このスキルは、Pythonライブラリやコマンドラインツールを使用してPDFファイルを処理するための包括的なガイドです。pypdf、pdfplumber、reportlabなどのライブラリを使った基本的な操作(読み取り、テキスト抽出、分割、結合、回転)から、qpdfやpdftotextなどのCLIツールによる処理、スキャンPDFのOCR処理、パスワード保護、透かし追加といった高度なタスクまでをカバーしています。特に、PDFフォームの入力にはFORMS.md、より高度なライブラリや詳細な例にはREFERENCE.mdを参照するよう指示する選択的読み取りルールを採用しており、開発者やAIエージェントが効率的に作業を進められるよう設計されています。また、ReportLabでのサブスクリプト/スーパースクリプトの正しい記述方法など、実践的な注意点も含まれています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Anhvu1107/all-agent-skill/tree/HEAD/.agent/skills/pdf

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

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

ドキュメント

PDF処理ガイド

選択的読み取りルール

まず以下から開始してください:

  • references/usage-routing.md
  • references/quality-checklist.md

次に、ユーザーの実際のタスクに一致する継承済みドキュメント、スクリプト、アセット、または例のみを読み込んでください。

選択的読み取りルール

まず以下から開始してください:

  • references/senior-master-standard.md
  • references/task-routing.md
  • references/quality-checklist.md

次に以下を読み込んでください:

  • AcroFormまたはフィールド入力作業の場合は forms.md
  • より幅広いツールやライブラリの調査が必要な場合は reference.md

概要

このガイドでは、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, "reportlabで作成されたPDFです")

# 線の追加
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)

下付き文字と上付き文字

重要: ReportLabのPDFでは、Unicodeの下付き/上付き文字(₀₁₂₃₄₅₆₇₈₉、⁰¹²³⁴⁵⁶⁷⁸⁹)を決して使用しないでください。組み込みフォントにはこれらのグリフが含まれておらず、黒い塗りつぶしの四角としてレンダリングされます。

代わりに、ParagraphオブジェクトでReportLabのXMLマークアップタグを使用してください:

from reportlab.platypus import Paragraph
from reportlab.lib.styles import getSampleStyleSheet

styles = getSampleStyleSheet()

# 下付き文字:<sub>タグを使用
chemical = Paragraph("H<sub>2</sub>O", styles['Normal'])

# 上付き文字:<super>タグを使用
squared = Paragraph("x<super>2</super> + y<super>2</super>", styles['Normal'])

キャンバス描画テキスト(Paragraphオブジェクトではない)の場合は、Unicodeの下付き/上付き文字を使用する代わりに、手動でフォントサイズと位置を調整してください。

コマンドラインツール

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の分割pypdf1ファイルにつき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.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches 007: Security audit, hardening, threat modeling (STRIDE/PASTA), Red/Blue Team, OWASP checks, code review, incident response, and infrastructure security for any project.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Agentfolio: Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Animejs Animation: Advanced JavaScript animation library skill for creating complex, high-performance web animations.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Astropy: Astropy is the core Python package for astronomy, providing essential functionality for astronomical research and data analysis.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Astro: Build content-focused websites with Astro — zero JS by default, islands architecture, multi-framework components, and Markdown/MDX support.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Emotional ARC Designer: One sentence - what this skill does and when to invoke it

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Fixing Motion Performance: Audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches I18n Localization: Internationalization and localization patterns.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Interactive Portfolio: Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches JQ: Expert jq usage for JSON querying, filtering, transformation, and pipeline integration.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Landing Page Generator: Generates high-converting Next.js/React landing pages with Tailwind CSS.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches LEX: Centralized ''Truth Engine'' for cross-jurisdictional legal context (US, EU, CA) and contract scaffolding.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Magic Animator: AI-powered animation tool for creating motion in logos, UI, icons, and social media assets.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Makepad Animation: CRITICAL: Use for Makepad animation system.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Nextjs APP Router Patterns: Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

Anhvu1107/all-agent-skill

ALWAYS use this when the user mentions Nextjs Best Practices, asks to build, debug, review, document, automate, test, configure, migrate, or make decisions in this domain, or the task clearly depends on Nextjs Best Practices; scope: Next.js App Router principles. Apply the bundled workflow, references, scripts, Senior Master standard, and Codex strict review gate before final output.

Anhvu1107/all-agent-skill

description: ALWAYS use this when the work is specifically about modern Next.js or React architecture, data flow, rendering strategy, routing, or performance-sensitive frontend behavior.

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches Nextjs Supabase Auth: Expert integration of Supabase Auth with Next.js App Router

Anhvu1107/all-agent-skill

ALWAYS use this when the request matches React Nextjs Development: React and Next.js 14+ application development with App Router, Server Components, TypeScript, Tailwind CSS, and modern frontend patterns.

Anhvu1107/all-agent-skill

ALWAYS use this when working with Remotion code, video compositions, rendering logic, timing, media assets, or React-based motion workflows.

関連スキル