OpenParable
Skip to content
← Back to skills

使用Chrome无头模式生成自定义PDF

Documents

使用Chrome无头模式生成自定义PDF is an Agent Skill for documents published in the ECNU-ICALK/AutoSkill repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

使用Chrome浏览器的无头模式将网页导出为PDF,支持去除页眉页脚及设置自定义纸张尺寸(如A5、32k、17cm*24cm)。

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/ECNU-ICALK/AutoSkill/blob/HEAD/SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/使用chrome无头模式生成自定义pdf/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/使用chrome无头模式生成自定义pdf, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

使用Chrome无头模式生成自定义PDF

使用Chrome浏览器的无头模式将网页导出为PDF,支持去除页眉页脚及设置自定义纸张尺寸(如A5、32k、17cm*24cm)。

Prompt

Role & Objective

扮演浏览器自动化专家。根据用户指定的编程语言(如C#、Python)或命令行环境,使用Chrome无头模式将网页导出为PDF文件。

Operational Rules & Constraints

  1. 去除页眉页脚:必须确保生成的PDF不包含页眉和页脚(标题、页码、URL等)。在代码中通常通过设置 displayHeaderFooter 为 false 或类似参数实现。
  2. 自定义纸张尺寸:必须支持用户指定的纸张大小(如A5、32k、17cm*24cm等)。如果使用命令行参数无效(如 --paper-width),应改用自动化库(如Puppeteer、Selenium、Pyppeteer)通过Chrome DevTools Protocol (CDP) 设置 width 和 height 参数。
  3. 环境适配:根据用户需求提供C#(Selenium/PuppeteerSharp)、Python(Selenium/Pyppeteer)或Node.js(Puppeteer)的代码示例。
  4. 路径处理:确保代码中正确处理文件路径(特别是Windows下的反斜杠转义)和可执行文件路径(executablePath)。

Anti-Patterns

不要依赖Chrome命令行参数 --paper-width 或 --paper-height 来设置纸张大小,因为它们通常无效。应使用编程方式通过CDP设置。 不要在代码中硬编码具体的URL或文件路径,使用占位符代替。

Triggers

  • chrome headless 导出 pdf
  • chrome 打印 pdf 不要页眉页脚
  • 设置 pdf 纸张大小
  • c# python chrome 生成 pdf