压缩 PDF

压缩 PDF 可在尽量保留视觉质量的同时减小 PDF 文档的文件大小。用户可以调整压缩级别,在文件大小与文档清晰度之间找到合适的平衡。

compress-pdf.md
下载
---
name: compress-pdf
description: "Compress PDF reduces the file size of PDF documents while preserving as much visual quality as possible. Users can adjust the compression level to find the right balance between file size and document clarity. Use this skill when the user asks to compress pdf via the Cross Service Solutions API."
---

# Compress PDF

## Solution Description

Compress PDF reduces the file size of PDF documents while preserving as much visual quality as possible. Users can adjust the compression level to find the right balance between file size and document clarity.

*This widget is provided by PDF24. Get your own widget to enable your visitors to convert to PDF

## Input

| Parameter | Type | Required | Description |
|---|---|---|---|
| `file` | file | Yes | PDF Document |
| `imageQuality` | number | Yes | Values in % from 0 to 100. Smaller value reduces size of PDF File but also the quality. |
| `dpi` | number | Yes | Dots per inch from 72 to 300. Smaller value reduces size of PDF File but also quality. |

## Expected Outcome

Executing this solution creates an asynchronous job. Poll the "Get Result" endpoint
until `status` is no longer `pending` — a `done` status means `output` will contain
the result (`output.result`, `output.data`, and/or `output.files[]` depending on the
solution), while a `failed` status means the job could not be completed.

## Execute Solution

This is a free endpoint — no `Authorization` header is required.

```bash
curl -D - -X POST 'https://api.cross-service-solutions.com/solutions/solutions/free/62' \
  -F 'file=@/path/to/file.pdf' \
  -F 'imageQuality=<number>' \
  -F 'dpi=<number>'
```

The response sets `Solution_id` and `Solution_uuid` cookies via `Set-Cookie` headers
(visible with `-D -`). Read their values — they're required for the "Get Result"
request below.

## Get Result

```bash
curl --location 'https://api.process-machine.com/solutions/solutions/free/solution/latest' \
  --header 'Cookie: Solution_id=<id>; Solution_uuid=<uuid>'
```

Replace `<id>` and `<uuid>` with the `Solution_id` and `Solution_uuid` values captured
from the "Execute Solution" response headers. This endpoint lives on a different
domain than "Execute Solution", so the cookies must be passed explicitly via the
`Cookie` header — they won't be forwarded automatically across domains by a reused
cookie jar.

**Response example:**

```json
{
    "id": 101362,
    "name": "Free - Compress PDF",
    "status": "done",
    "steps": [
        { "name": "Compress PDF", "status": "done" },
        { "name": "Compress PDF", "status": "done" }
    ],
    "output": {
        "result": "",
        "data": null,
        "files": [
            { "name": "compressed.pdf", "path": "https://storage.googleapis.com/..." }
        ]
    }
}
```

**Polling behavior:**
- Poll every 3 seconds
- Timeout after 60 seconds (20 attempts) — if still `pending`, tell the user the
  job is taking longer than expected and offer to keep waiting or retry
- On `done`: download the file(s) from `output.files[].path` (a signed, time-limited
  URL) — or check `output.result`/`output.data` if `files` is empty
- On `failed`: surface the `error` field (if present) to the user in plain language;
  do not retry automatically more than once

## Error Handling

| Scenario | Response |
|---|---|
| Missing required parameter(s) | Ask the user for the missing field(s): `file`, `imageQuality`, `dpi` |
| Invalid or unreadable file | Tell the user which file couldn't be processed and ask them to check the format or re-upload |
| API returns `failed` status | Report the failure reason if available; offer to retry |
| `403 Forbidden` on Get Result | The `Solution_id`/`Solution_uuid` values are missing, incorrect, or expired — re-run "Execute Solution" and retry with the fresh values |

如何使用 AI 智能体技能

1

下载并上传技能

下载你想使用的技能,然后将其上传到你的工作区。上传后,智能体便可以在执行任务时引用并应用该技能。

2

启用所需的外部域名

部分技能需要访问网络才能正常运行。运行前,请将以下域名加入允许列表:

  • api.cross-service-solutions.com — 用于向我们的服务发送 API 请求
  • api.process-machine.com — 用于获取技能任务的结果
  • storage.googleapis.com — 用于下载辅助文件和资源

如果未启用这些域名,依赖外部调用的技能可能会失败或返回不完整的结果。

社区

帮助我们 共同成长

您的意见让这个目录对所有人都更有价值。分享您所知道的——不到一分钟。

建议解决方案

知道一个能解决实际问题的工具或工作流程?帮助其他人发现它——我们的团队会审核每一份提交。

发送反馈

发现错误、缺失内容或值得改进的地方?我们阅读每一条消息并采纳最佳建议。