PDF Tools Suite

VerifiedSafe

Provides Python code snippets for creating PDF documents with text, images, and tables using ReportLab, as well as merging, splitting, and extracting text and tables from existing PDFs using PyPDF and pdfplumber. Useful for automating PDF generation and data extraction tasks.

Sby Skills Guide Bot
DevelopmentIntermediate
6/2/2026
Claude Code
#pdf#reportlab#pypdf#pdfplumber#document-generation

Recommended for

Automated summary

This guide provides instructions for creating, editing, merging, splitting, and extracting text or tables from PDF files using the Python libraries reportlab, pypdf, and pdfplumber.

Strengths

  • Covers multiple common PDF operations
  • Uses lightweight, well-maintained libraries
  • Clear, ready-to-use code examples
  • Supports complex report generation with images and tables

Limitations

  • Requires a Python environment
  • Text extraction may be inaccurate for poorly formatted PDFs
  • Does not handle PDF forms or annotations
When to use it

When you need to automate PDF creation, merging, or content extraction in a Python workflow.

When not to use it

For advanced PDF processing (OCR, interactive forms, digital signatures), use specialized tools like Adobe Acrobat or PyMuPDF.

Security analysis

Safe
Quality score90/100

The skill provides Python code for local PDF creation, merging, splitting, and text/table extraction using well-known libraries. It does not include destructive commands, data exfiltration, or network activity. The pip install suggestion is for standard, trusted packages.

No concerns found

How this analysis is made

Examples

Créer un rapport PDF
Génère un script Python pour créer un rapport PDF contenant un titre, un résumé, une image et un tableau structuré, en utilisant reportlab.
Fusionner plusieurs PDF
Écris un script Python avec pypdf pour fusionner tous les fichiers PDF du dossier actuel en un seul fichier nommé merged.pdf.
Extraire le texte d'un PDF
Utilise pdfplumber pour extraire le texte de toutes les pages d'un fichier input.pdf et l'afficher dans la console.

name: PDF 工具集 description: PDF 创建、编辑、合并、拆分工具集

PDF 操作工具集

本技能提供 PDF 文档操作的完整指南。

依赖库

pip install reportlab pypdf pdfplumber

1. 创建 PDF (reportlab)

基础文档

from reportlab.lib.pagesizes import A4, letter
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch, cm
from reportlab.platypus import (
    SimpleDocTemplate, Paragraph, Spacer, Image,
    Table, TableStyle, PageBreak
)
from reportlab.lib import colors

# 创建文档
doc = SimpleDocTemplate(
    "output.pdf",
    pagesize=A4,
    rightMargin=72,
    leftMargin=72,
    topMargin=72,
    bottomMargin=72
)

# 获取样式
styles = getSampleStyleSheet()

# 构建内容
story = []

# 添加标题
story.append(Paragraph("报告标题", styles['Heading1']))
story.append(Spacer(1, 12))

# 添加段落
story.append(Paragraph("这是正文内容。", styles['Normal']))
story.append(Spacer(1, 12))

# 生成 PDF
doc.build(story)

添加图片

from reportlab.platypus import Image

# 添加图片(指定宽度,保持比例)
img = Image("chart.png", width=400)
story.append(img)

添加表格

from reportlab.platypus import Table, TableStyle
from reportlab.lib import colors

data = [
    ['标题1', '标题2', '标题3'],
    ['数据1', '数据2', '数据3'],
    ['数据4', '数据5', '数据6'],
]

table = Table(data)
table.setStyle(TableStyle([
    ('BACKGROUND', (0, 0), (-1, 0), colors.grey),
    ('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
    ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
    ('FONTSIZE', (0, 0), (-1, 0), 14),
    ('BOTTOMPADDING', (0, 0), (-1, 0), 12),
    ('BACKGROUND', (0, 1), (-1, -1), colors.beige),
    ('GRID', (0, 0), (-1, -1), 1, colors.black),
]))

story.append(table)

自定义样式

# 自定义段落样式
custom_style = ParagraphStyle(
    'CustomStyle',
    parent=styles['Normal'],
    fontSize=12,
    leading=16,
    spaceAfter=12,
    textColor=colors.darkblue,
)

2. 合并 PDF (pypdf)

from pypdf import PdfMerger

merger = PdfMerger()

# 添加 PDF 文件
merger.append("file1.pdf")
merger.append("file2.pdf")
merger.append("file3.pdf")

# 写入合并后的文件
merger.write("merged.pdf")
merger.close()

3. 拆分 PDF

from pypdf import PdfReader, PdfWriter

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)

4. 提取文本 (pdfplumber)

import pdfplumber

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

5. 提取表格

import pdfplumber

with pdfplumber.open("input.pdf") as pdf:
    for page in pdf.pages:
        tables = page.extract_tables()
        for table in tables:
            for row in table:
                print(row)

6. 完整报告示例

from reportlab.lib.pagesizes import A4
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import (
    SimpleDocTemplate, Paragraph, Spacer, Image, Table, TableStyle, PageBreak
)
from reportlab.lib import colors
from reportlab.lib.units import inch
from datetime import datetime

def create_research_report(
    output_path: str,
    title: str,
    summary: str,
    findings: list,
    charts: list,
    data_table: list
):
    """创建研究报告 PDF"""

    doc = SimpleDocTemplate(output_path, pagesize=A4)
    styles = getSampleStyleSheet()
    story = []

    # 封面
    story.append(Spacer(1, 2*inch))
    story.append(Paragraph(title, styles['Title']))
    story.append(Spacer(1, 0.5*inch))
    story.append(Paragraph(
        f"生成日期: {datetime.now().strftime('%Y-%m-%d')}",
        styles['Normal']
    ))
    story.append(PageBreak())

    # 执行摘要
    story.append(Paragraph("执行摘要", styles['Heading1']))
    story.append(Spacer(1, 12))
    story.append(Paragraph(summary, styles['Normal']))
    story.append(Spacer(1, 24))

    # 关键发现
    story.append(Paragraph("关键发现", styles['Heading1']))
    story.append(Spacer(1, 12))
    for i, finding in enumerate(findings, 1):
        story.append(Paragraph(f"{i}. {finding}", styles['Normal']))
        story.append(Spacer(1, 6))
    story.append(Spacer(1, 24))

    # 图表
    if charts:
        story.append(Paragraph("数据可视化", styles['Heading1']))
        story.append(Spacer(1, 12))
        for chart_path in charts:
            try:
                img = Image(chart_path, width=5*inch)
                story.append(img)
                story.append(Spacer(1, 12))
            except Exception as e:
                story.append(Paragraph(f"图表加载失败: {chart_path}", styles['Normal']))

    # 数据表格
    if data_table:
        story.append(Paragraph("详细数据", styles['Heading1']))
        story.append(Spacer(1, 12))
        table = Table(data_table)
        table.setStyle(TableStyle([
            ('BACKGROUND', (0, 0), (-1, 0), colors.HexColor('#4472C4')),
            ('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
            ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
            ('FONTSIZE', (0, 0), (-1, -1), 10),
            ('GRID', (0, 0), (-1, -1), 0.5, colors.grey),
            ('ROWBACKGROUNDS', (0, 1), (-1, -1), [colors.white, colors.HexColor('#E7E6E6')]),
        ]))
        story.append(table)

    # 生成 PDF
    doc.build(story)
    return output_path

# 使用示例
create_research_report(
    output_path="files/reports/research_report.pdf",
    title="市场研究报告",
    summary="本报告分析了...",
    findings=["发现1", "发现2", "发现3"],
    charts=["files/charts/chart1.png", "files/charts/chart2.png"],
    data_table=[
        ["指标", "2023", "2024", "增长率"],
        ["市场规模", "100亿", "120亿", "20%"],
        ["用户数", "1000万", "1500万", "50%"],
    ]
)

注意事项

  1. 中文支持:reportlab 默认不支持中文,需要注册中文字体:

    from reportlab.pdfbase import pdfmetrics
    from reportlab.pdfbase.ttfonts import TTFont
    pdfmetrics.registerFont(TTFont('SimHei', 'SimHei.ttf'))
    
  2. 图片格式:支持 PNG, JPG, GIF 格式

  3. 内存优化:处理大文件时使用流式处理

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/pdf-tools-suite-mm5t89a9/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/pdf-tools-suite-mm5t89a9' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/pdf-tools-suite-mm5t89a9/download' --output '.skill-downloads/pdf-tools-suite-mm5t89a9/SKILL.md.part' && mv '.skill-downloads/pdf-tools-suite-mm5t89a9/SKILL.md.part' '.skill-downloads/pdf-tools-suite-mm5t89a9/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

This file does not provide a usable name/description header for this native procedure. It remains available to download and inspect; use the manual method below.

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/pdf-tools-suite-mm5t89a9/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills