Communitygithub.com

bg-szy/TOP-SKILLS(PDF処理スキル)

PDFファイルに関するあらゆる操作を実行します。テキスト/表の読み取り、結合、分割、ページ回転、ウォーターマーク追加、新規作成、フォーム入力、暗号化/復号化、画像抽出、OCRなど、PDF関連のタスクすべてに対応します。

TOP-SKILLS(PDF処理スキル) とは?

このスキルは、PDFファイルの包括的な処理を可能にするためのAIエージェント向けガイドです。pypdf、pdfplumber、reportlabといったPythonライブラリや、pdftotext、qpdf、pdftkなどのコマンドラインツールを活用し、テキスト抽出、表抽出、PDFの結合・分割、ページ回転、ウォーターマーク追加、新規PDF作成、フォーム入力、パスワード暗号化/復号化、画像抽出、そしてスキャンPDFに対するOCR処理といった多様な操作をサポートします。特に、ユーザーが「.pdf」ファイルに言及したり、PDFの作成を要求した場合に自動的にこのスキルが呼び出されるよう設計されており、開発者やAIエージェントユーザーがPDF操作を効率的に自動化・統合するのに役立ちます。各操作には具体的なコード例が豊富に含まれており、迅速な実装が可能です。また、ReportLabでよくあるUnicode添え字問題への注意など、実践的な注意点もカバーしています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/bg-szy/TOP-SKILLS/tree/HEAD/skills/skills/pdf

お気に入りの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)}")

# テキストを抽出
テキスト = ""
for ページ in reader.pages:
    テキスト += ページ.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 ページ in reader.pages:
        writer.add_page(ページ)

with open("combined.pdf", "wb") as 出力:
    writer.write(出力)

PDFの分割

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

メタデータの抽出

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()

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

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

pdfplumber - テキストと表の抽出

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

import pdfplumber

with pdfplumber.open("document.pdf") as pdf:
    for ページ in pdf.pages:
        テキスト = ページ.extract_text()
        print(テキスト)

表の抽出

with pdfplumber.open("document.pdf") as pdf:
    for i, ページ in enumerate(pdf.pages):
        表リスト = ページ.extract_tables()
        for j, 表 in enumerate(表リスト):
            print(f"ページ {i+1} の表 {j+1}:")
            for 行 in 表:
                print(行)

高度な表抽出

import pandas as pd

with pdfplumber.open("document.pdf") as pdf:
    全表 = []
    for ページ in pdf.pages:
        表リスト = ページ.extract_tables()
        for 表 in 表リスト:
            if 表:  # 表が空でないか確認
                df = pd.DataFrame(表[1:], columns=表[0])
                全表.append(df)

# すべての表を結合
if 全表:
    combined_df = pd.concat(全表, 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
テキスト = ""
for i, image in enumerate(images):
    テキスト += f"ページ {i+1}:\n"
    テキスト += pytesseract.image_to_string(image)
    テキスト += "\n\n"

print(テキスト)

ウォーターマークを追加

from pypdf import PdfReader, PdfWriter

# ウォーターマークを作成(または既存のものを読み込む)
watermark = PdfReader("watermark.pdf").pages[0]

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

for ページ in reader.pages:
    ページ.merge_page(watermark)
    writer.add_page(ページ)

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

画像を抽出

# 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 ページ in reader.pages:
    writer.add_page(ページ)

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

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

クイックリファレンス

タスク最適なツールコマンド/コード
PDFの結合pypdfwriter.add_page(ページ)
PDFの分割pypdf1ページごとにファイル
テキスト抽出pdfplumberページ.extract_text()
表の抽出pdfplumberページ.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.

bg-szy/TOP-SKILLS

Brand-first landing page designer — runs a brand-identity interview (colors, typography, shape language), then generates and iterates on a polished landing page via Stitch with deployment-ready HTML. Use when the user asks to create, design, or build a landing page, homepage, or marketing page and has no established visual direction. Skip when they have a design mockup, need a dashboard or app UI, are working at component level, building a multi-page app, or restyling with known design tokens — use frontend-design instead.

bg-szy/TOP-SKILLS

Fill out Microsoft Azure Landing Zone (ALZ) Accelerator checklists by interviewing the user, mapping their Azure subscriptions, integrating IP addressing documentation, and applying Microsoft Cloud Adoption Framework best practices. Produces a completed Excel checklist (.xlsx) ready for ALZ deployment. Use this skill whenever the user mentions Azure Landing Zone, ALZ checklist, landing zone accelerator, platform landing zone configuration, ALZ bootstrap, hub-and-spoke setup, Azure network topology planning, or wants to fill out any ALZ-related checklist or configuration file. Also trigger when the user uploads an Excel file that contains tabs like "Accelerator - Bootstrap", "Accelerator - Bicep", or "Accelerator - Terraform".

bg-szy/TOP-SKILLS

Compose a premium, animated landing page section by section in Next.js + Tailwind + Motion (Framer Motion) — built on a real design system, with editorial copy and motion that feels human-crafted, not template-generated. Use when building or rebuilding a landing page, marketing site, or hero/feature/pricing/CTA sections that need to look production-ready and bespoke from day one.

bg-szy/TOP-SKILLS

Write high-converting landing page copy using proven frameworks like PAS (Problem-Agitate-Solution), AIDA, and StoryBrand. Creates headlines, value propositions, CTAs, and full page sections optimized for conversion. Use when users need landing page copy, sales page content, or marketing website text.

bg-szy/TOP-SKILLS

Optimize landing pages for conversions, performance, and SEO. Use when improving landing pages, increasing conversions, or optimizing page performance.

bg-szy/TOP-SKILLS

Review investment portfolios for risk, diversification, fees. Asset allocation recommendations, tax-loss harvesting, rebalancing.

bg-szy/TOP-SKILLS

Beads Viewer - Graph-aware triage engine for Beads projects. Computes PageRank, betweenness, critical path, and cycles. Use --robot-* flags for AI agents.

bg-szy/TOP-SKILLS

CI red? Call us. Pipeline fire brigade deploys. Use when user mentions CI failures, build errors, test failures, or pipeline issues. Do NOT load for: local builds, standard implementation work, reviews, or setup.

bg-szy/TOP-SKILLS

CASS Memory System - procedural memory for AI coding agents. Three-layer cognitive architecture with confidence decay, anti-pattern learning, cross-agent knowledge transfer, trauma guard safety system. Bun/TypeScript CLI.

bg-szy/TOP-SKILLS

Mandatory entry point: read this first for any request to make, create, edit, animate, or render a video, animation, or motion graphic, including a promo, explainer, captioned clip, title card, overlay, slideshow or interactive deck, Remotion port, or any HyperFrames HTML composition. Also use it to inspect, diagnose, validate, preview, publish, or batch-render an existing HyperFrames project. Inputs may be a website URL, GitHub PR, Figma design or URL, text or brief, existing footage, or music. It resumes project state, captures intent when applicable, selects and installs the owning workflow, and routes domain capabilities. HyperFrames is the default output framework unless the user explicitly chooses another framework for the deliverable or asks only to record a browser session.

bg-szy/TOP-SKILLS

Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences. Covers developer portfolios, designer portfolios, creative portfolios, and portfolios that convert visitors into opportunities.

bg-szy/TOP-SKILLS

Use when the user asks to "pre-launch check the landing page", "run a Quality-Score preflight", or "verify ad-to-page message match before launch"; produces an ad↔page continuity report — message-match gaps, above-the-fold check, page-speed read, form-friction count, mobile-render flags — as a pass/fix punch list. Not for redesigning or rewriting the page — use landing-optimizer; not for scoring the account or the RQS — use ad-account-auditor. 落地页体验预检/广告落地页一致性检查

bg-szy/TOP-SKILLS

Use when the user asks to "optimize our landing page for influencer traffic", "fix our promo-code landing page", or "improve conversion from a creator campaign"; produces a message-match audit, page-structure and social-proof recommendations, a promo-code/CTA conversion plan, and an A/B test roadmap. Not for measuring campaign results after launch — use performance-analyzer.

bg-szy/TOP-SKILLS

Audit a landing page, sales page or checkout page for conversion leaks and return a fix list ordered by expected revenue impact. Use when asked to review, critique or improve a landing page, sales page, opt-in page, product page or checkout flow, when conversion rate is low, when paid traffic is not converting, or when someone asks "why isn't this page converting" or wants a CRO / landing page review.

bg-szy/TOP-SKILLS

Landing page conversion optimization with layout rules, hero section design, and CTA psychology. Covers above-the-fold formula, social proof placement, mobile design, and F-pattern reading. Use for: startup landing pages, product pages, SaaS marketing, conversion optimization. Triggers: landing page, hero section, above the fold, conversion optimization, landing page design, cta button, hero image, landing page layout, saas landing page, product page design, conversion rate, landing page best practices

bg-szy/TOP-SKILLS

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

bg-szy/TOP-SKILLS

Landing page conversion optimization with layout rules, hero section design, and CTA psychology. Covers above-the-fold formula, social proof placement, mobile design, and F-pattern reading. Use for: startup landing pages, product pages, SaaS marketing, conversion optimization. Triggers: landing page, hero section, above the fold, conversion optimization, landing page design, cta button, hero image, landing page layout, saas landing page, product page design, conversion rate, landing page best practices

bg-szy/TOP-SKILLS

Account assets, equity and fund positions, P&L, cash flow records, account statements, margin ratios, buy-power estimates, order management, and DCA recurring investments via Longbridge (most require Trade permission). Frameworks: portfolio diagnosis, rebalancing, asset allocation, risk analysis (VaR/CVaR), performance attribution, and tax-loss harvesting. Triggers: "持仓", "账户", "盈亏", "资产", "对账单", "下单", "买入", "卖出", "撤单", "定投", "组合诊断", "再平衡", "资产配置", "风险分析", "绩效归因", "税损收割", "持倉", "賬戶", "盈虧", "對賬單", "下單", "買入", "賣出", "組合診斷", "再平衡", "稅損收割", "positions", "portfolio", "P&L", "order", "buy", "sell", "DCA", "statement", "risk analysis", "rebalancing", "tax harvesting", "我的风险", "持仓风险", "风险敞口", "資產", "資產配置", "風險分析", "績效歸因", "撤單

bg-szy/TOP-SKILLS

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

bg-szy/TOP-SKILLS

Process video files with audio extraction, format conversion (mp4, webm), and Whisper transcription. Use when user mentions video conversion, audio extraction, transcription, mp4, webm, ffmpeg, or whisper transcription.

関連スキル