添加水印 API
向 PDF 添加文字或图片水印。
功能说明
ComPDF Self-hosted 通过 multipart/form-data 接收文件和 request JSON 字符串,并将参数转发给私有化 PDF SDK。成功时直接返回结果文件流。
同步执行
| 项目 | 值 |
|---|---|
| 认证 | x-api-key: your_api_key_here |
| 请求地址 | POST http://localhost:8080/api/v1/process/pdf/watermark/add |
| 请求类型 | multipart/form-data |
| 成功响应 | 结果文件流 |
请求参数
| 参数名 | 类型 | 说明 | 是否必填 |
|---|---|---|---|
file | File | 源 PDF 文件。 | 是 |
imageFile | File | 图片水印文件,仅当 request.type 为 image 时需要。 | 否 |
request | String | JSON 字符串,包含下方 PDF SDK 参数。若省略 request,其他非文件 form-data 字段会作为 request 对象转发。 | 否 |
Request 参数
以下字段放入 request JSON 字符串中。
| 参数名 | 类型 | 作用 |
|---|---|---|
type | String 或 Integer | ComPDF Web 使用的 PDF 转 JSON 内容范围。0 表示文本,1 表示表格,2 表示全部。 |
text | String | 水印文字。 |
fontSize | Number | 文字水印字号。 |
fontColor | String | 文字颜色,例如 #D32F2F。 |
opacity | Number | 水印透明度,常用范围为 0 到 1。 |
rotation | Number | 水印旋转角度,单位为度。 |
horizalign | String | 水平对齐方式,例如 left、center 或 right。 |
vertalign | String | 垂直对齐方式,例如 top、center 或 bottom。 |
horizOffset | Number | 水平偏移量,单位为 point。 |
vertOffset | Number | 垂直偏移量,单位为 point。 |
horizontalSpacing | Number | 平铺水印的水平间距。 |
verticalSpacing | Number | 平铺水印的垂直间距。 |
fullScreen | Boolean | 是否在页面内平铺水印。 |
pages | String 或 Number[] | 需要处理的页面。示例:1、1,3-5、[1,3,4,5],支持时可传 all。 |
password | String | 源 PDF 打开密码。部分路由在 SDK 接口不直接接收该字段时会在转发前移除。 |
outputFileName | String | 可选输出文件名。传入后会作为首选下载文件名。 |
请求示例
bash
curl -X POST "http://localhost:8080/api/v1/process/pdf/watermark/add" \
-H "x-api-key: your_api_key_here" \
-F "[email protected]" \
-F 'request={"type":"text","text":"ComPDF","fontSize":"","fontColor":"","opacity":0.3}'响应
成功时返回处理后的文件流。响应头包含 Content-Type 和 Content-Disposition。失败时返回统一错误 JSON。