360 Secure SkillHub
360 安全技能中心

Smart Image to PDF

通过 Python 脚本把多张图片或截图按 A4 可打印宽度等比缩放并紧凑排布成分页 PDF,自动裁剪白边,换页时用像素分析寻找空白行以避免切断文字,输出 300 DPI 可打印 PDF,适合试卷等截图合并。

wxttt
wxttt
热度 53.36
最近更新 2026-05-11 17:30:43
分类:效率依赖:代码执行 / 读写文件应用场景:文件转换 / 自动化脚本

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add smart-image-to-pdf
Metadata
name
image-to-pdf
description
Combine multiple image screenshots into a paginated A4 PDF. Intelligently handles page breaks to avoid cutting through text. Use when the user wants to combine, merge, or stitch images/screenshots into a PDF, especially exam papers or documents.

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

uv run --with Pillow --with numpy python3 <path-to-this-skill>/scripts/combine.py <input> -o <output.pdf>

Input formats:

  • A directory: python scripts/combine.py ./my_images/ -o result.pdf
  • Multiple files: python scripts/combine.py img1.png img2.png -o result.pdf

Optional flags:

  • --margin <px>: page margin in pixels at 300dpi (default: 80, ~7mm)
  • --no-trim: disable automatic whitespace border trimming
  • --dpi <n>: 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
  2. Scales all images to the same width (A4 printable width)
  3. Greedily packs images onto A4 pages (tight layout, no gaps)
  4. When a page break is needed, uses pixel analysis to find whitespace rows so text is never cut
  5. Outputs a 300 DPI PDF ready for printing