Communitygithub.com

Anhvu1107/all-agent-skill

當任務涉及讀取、提取、分割、合併、旋轉、建立、驗證、OCR、填寫表單或任何其他產生或修改 PDF 檔案的操作時,務必使用此技能。

all-agent-skill 是什麼?

這是一個專為 AI 代理(如 Claude Code、Cursor、Codex)設計的綜合性 PDF 處理技能,涵蓋從基本操作到進階功能的完整流程。它支援多種平台與工具,包括 Python 函式庫(pypdf、pdfplumber、reportlab)和命令列工具(pdftotext、qpdf、pdftk)。該技能提供詳細的程式碼範例,指導如何合併、分割、旋轉、提取文字與表格、建立 PDF、執行 OCR、新增浮水印以及設定密碼保護。其核心設計遵循「選擇性閱讀規則」,代理會先讀取 `references/` 目錄下的路由與檢查清單文件,再根據具體任務(如表單填寫或進階功能)載入對應的 `forms.md` 或 `reference.md`,確保每次操作都能快速定位到最相關的指導。此外,技能特別強調避免在 reportlab 中使用 Unicode 上下標字符,並提供正確的 XML 標籤替代方案,以解決常見的渲染問題。對於掃描文件 OCR 和表單填寫等複雜任務,它也提供了明確的依賴安裝與步驟指引。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Anhvu1107/all-agent-skill/tree/HEAD/.agent/skills/pdf

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

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"第 {j+1} 個表格 (位於第 {i+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)

快速參考

任務最佳工具命令/程式碼
合併 PDFpypdfwriter.add_page(page)
分割 PDFpypdf每個頁面一個檔案
提取文字pdfplumberpage.extract_text()
提取表格pdfplumberpage.extract_tables()
建立 PDFreportlabCanvas 或 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.

相關技能