首页龙虾技能列表 › 自动从中间空白处切割A3试卷a3-pdf-splitter — 技能工具

自动从中间空白处切割A3试卷a3-pdf-splitter — 技能工具

v1.0.0

智能A3试卷PDF切分工具,自动识别试卷中间的空白位置进行切分,将A3格式的试卷PDF转换为A4格式方便打印。当用户提到"切分A3试卷"、"A3转A4"、"PDF切分"、"试卷打印"、"拆分试卷PDF"等相关需求时必须使用此技能。

0· 81·0 当前·0 累计
by @boxertan·MIT-0
下载技能包
License
MIT-0
最后更新
2026/4/3
安全扫描
VirusTotal
无害
查看报告
OpenClaw
安全
high confidence
The skill's code, instructions, and dependencies are consistent with its stated purpose (splitting A3 PDFs into A4) and do not request unrelated credentials, network access, or elevated persistence.
评估建议
This skill appears coherent and safe for its purpose, but follow standard precautions before installing: (1) install pypdfium2/pillow in a dedicated virtual environment to avoid system-wide changes; (2) confirm pypdfium2's packaging for your platform (it may include native binaries or require build tools); (3) test on non-sensitive/sample PDFs first (the script will overwrite the output path if it exists); (4) if you are concerned about running third-party code, review the included Python file (...
详细分析 ▾
用途与能力
The name/description (A3→A4 PDF splitting) matches the included script and SKILL.md. Required actions (render PDF, find middle whitespace, crop, save PDF) are exactly what you'd expect; there are no unrelated credentials, binaries, or config paths.
指令范围
SKILL.md instructs installing pypdfium2 and pillow and calling the provided split function or script. The runtime instructions only read the user-supplied input PDF and write the output PDF; they do not access other files, environment variables, or external endpoints.
安装机制
There is no custom install script; the README/INSTALL ask you to pip install pypdfium2 and pillow. Using pip is normal; note pypdfium2 provides native PDFium bindings (may pull native binaries or require build tools), but this is proportional to the task.
凭证需求
The skill requests no environment variables or credentials. It only needs read access to the input PDF and write access to the output path — appropriate and minimal for the stated functionality.
持久化与权限
always is false; the skill does not request persistent/system-level changes or modify other skills. It runs as a simple script and does not enable autonomous elevated privileges.
安全有层次,运行前请审查代码。

License

MIT-0

可自由使用、修改和再分发,无需署名。

运行时依赖

无特殊依赖

版本

latestv1.0.02026/4/3

自动从中间空白处切割A3试卷 Automatically cut A3 test papers from the middle blank space.

● 无害

安装命令 点击复制

官方npx clawhub@latest install a3-pdf-splitter
镜像加速npx clawhub@latest install a3-pdf-splitter --registry https://cn.clawhub-mirror.com

技能文档

功能说明

将A3格式的试卷PDF文件智能切分为A4格式,方便打印。工具会自动识别页面中间的最佳空白位置进行切割,避免切到文字内容。

  • 支持横向A3页面:左右切分为两个A4页面
  • 支持纵向A3页面:上下切分为两个A4页面
  • 400DPI高分辨率输出,保证打印质量
  • 自动保留原PDF的所有页面顺序

依赖安装

使用前需要安装依赖包:
pip install pypdfium2 pillow

使用方法

当用户需要切分A3试卷PDF时,按照以下步骤操作:

  • 获取输入PDF文件路径和输出路径
  • 调用切分脚本进行处理
  • 告知用户处理结果和输出文件位置

示例调用

from split_a3_smart import split_a3_to_a4_smart

# 切分A3试卷PDF split_a3_to_a4_smart("输入文件路径.pdf", "输出文件路径.pdf")

脚本代码

import pypdfium2 as pdfium
from PIL import Image
import os

def find_best_split_position(img, is_horizontal=True): """ 智能寻找最佳切割位置:在中间区域寻找最空白的列/行 is_horizontal=True:左右切(找最佳列);False:上下切(找最佳行) """ # 转为灰度图像 gray_img = img.convert('L') pixels = list(gray_img.getdata()) width, height = gray_img.size if is_horizontal: # 左右切:计算每列的像素和,和越大越空白(255是纯白色) middle_start = int(width 0.45) middle_end = int(width 0.55) max_sum = -1 best_x = middle_start for x in range(middle_start, middle_end): col_sum = 0 for y in range(height): col_sum += pixels[y width + x] if col_sum > max_sum: max_sum = col_sum best_x = x return best_x else: # 上下切:计算每行的像素和 middle_start = int(height 0.45) middle_end = int(height 0.55) max_sum = -1 best_y = middle_start for y in range(middle_start, middle_end): row_sum = 0 for x in range(width): row_sum += pixels[y width + x] if row_sum > max_sum: max_sum = row_sum best_y = y return best_y

def split_a3_to_a4_smart(input_path, output_path): # 打开PDF文件 pdf = pdfium.PdfDocument(input_path) output_images = [] for page_num in range(len(pdf)): page = pdf[page_num] width, height = page.get_size() # 渲染页面为高分辨率图像(400 DPI) scale = 400 / 72 bitmap = page.render(scale=scale) img = bitmap.to_pil() # A3横向:左右切 if width > height: split_x = find_best_split_position(img, is_horizontal=True) print(f"第{page_num+1}页最佳切割位置:x={split_x} (总宽度{img.width})") # 左半部分 left_img = img.crop((0, 0, split_x, img.height)) output_images.append(left_img) # 右半部分 right_img = img.crop((split_x, 0, img.width, img.height)) output_images.append(right_img) else: # A3纵向:上下切 split_y = find_best_split_position(img, is_horizontal=False) print(f"第{page_num+1}页最佳切割位置:y={split_y} (总高度{img.height})") # 上半部分 top_img = img.crop((0, 0, img.width, split_y)) output_images.append(top_img) # 下半部分 bottom_img = img.crop((0, split_y, img.width, img.height)) output_images.append(bottom_img) # 保存为PDF if output_images: output_images[0].save( output_path, "PDF", resolution=400, save_all=True, append_images=output_images[1:] ) print(f"\n处理完成!输出文件:{output_path}") print(f"原始页数:{len(pdf)},切分后页数:{len(output_images)}")

返回结果

处理完成后,告知用户:
  • 输出文件的保存路径
  • 原始页数和切分后的页数
  • 每个页面的切割位置(可选)

注意事项

  • 输入文件必须是PDF格式
  • 输出文件路径需要有写入权限
  • 大文件处理可能需要较长时间,请耐心等待
  • 建议输出文件名包含"_A4切分版"等标识,方便区分
数据来源:ClawHub ↗ · 中文优化:龙虾技能库
OpenClaw 技能定制 / 插件定制 / 私有工作流定制

免费技能或插件可能存在安全风险,如需更匹配、更安全的方案,建议联系付费定制

了解定制服务