Image to PDF
Combine multiple image screenshots (typically exam paper questions) into a well-formatted, paginated A4 PDF that is ready for printing.
When to Use
Trigger this skill when the user wants to:
- - Combine / merge / stitch images into a PDF
- Put screenshots together into a printable document
- Create a PDF from exam paper photos or screenshots
- Pack question images onto A4 pages for printing
Look for phrases like: "拼到一起", "合成PDF", "拼接", "打印", "combine images", "merge into PDF", etc.
How to Use
This skill includes a Python script at scripts/combine.py (relative to this SKILL.md).
Step 1: Identify inputs and output
From the user's request, extract:
- - Input: a directory path or list of image file paths
- Output: the desired PDF output path (default:
output.pdf in the input directory)
Step 2: Run the script
Use uv run to handle dependencies automatically (no manual install needed):
CODEBLOCK0
Input formats:
- - A directory: INLINECODE3
- Multiple files: INLINECODE4
Optional flags:
- -
--margin <px>: page margin in pixels at 300dpi (default: 80, ~7mm) - INLINECODE6 : disable automatic whitespace border trimming
- INLINECODE7 : output DPI (default: 300)
Step 4: Report result
Tell the user:
- - How many images were processed
- How many PDF pages were generated
- The output file path
What the Script Does
- 1. Loads images, auto-trims whitespace borders
- Scales all images to the same width (A4 printable width)
- Greedily packs images onto A4 pages (tight layout, no gaps)
- When a page break is needed, uses pixel analysis to find whitespace rows so text is never cut
- Outputs a 300 DPI PDF ready for printing
图像转PDF
将多张图像截图(通常是试卷题目)合并为格式规范、分页的A4 PDF,方便直接打印。
使用场景
当用户想要执行以下操作时触发此技能:
- - 将图像合并/拼接为PDF
- 将截图整合为可打印文档
- 从试卷照片或截图创建PDF
- 将题目图像排列到A4页面进行打印
注意识别以下关键词:拼到一起、合成PDF、拼接、打印、combine images、merge into PDF等。
使用方法
本技能包含一个Python脚本,位于scripts/combine.py(相对于本SKILL.md文件)。
第一步:确定输入和输出
根据用户请求提取以下信息:
- - 输入:目录路径或图像文件路径列表
- 输出:所需的PDF输出路径(默认:输入目录下的output.pdf)
第二步:运行脚本
使用uv run自动处理依赖项(无需手动安装):
bash
uv run --with Pillow --with numpy python3 <此技能路径>/scripts/combine.py <输入> -o <输出.pdf>
输入格式:
- - 目录:python scripts/combine.py ./my_images/ -o result.pdf
- 多个文件:python scripts/combine.py img1.png img2.png -o result.pdf
可选参数:
- - --margin <像素>:300dpi下的页面边距像素值(默认:80,约7mm)
- --no-trim:禁用自动白边裁剪
- --dpi <数值>:输出DPI(默认:300)
第四步:报告结果
告知用户:
- - 处理了多少张图像
- 生成了多少页PDF
- 输出文件路径
脚本功能说明
- 1. 加载图像,自动裁剪白边
- 将所有图像缩放到相同宽度(A4可打印宽度)
- 将图像紧凑排列到A4页面上(紧密布局,无间隙)
- 需要分页时,通过像素分析找到空白行,确保文字不被截断
- 输出300 DPI的PDF,可直接打印