添加水印 Word
PDF4me 添加水印 Word 是一个 REST 该端点会在每一页的文本后面添加图像水印。 Word 文档。 POST .docx 文件和水印图像 Base64 到 office/ApiV2Word/AddWatermark调整缩放比例、透明度和对齐方式,然后解码带有水印的文件。 JSON 回复。 PNG, JPG, JPEG支持 BMP 和 GIF 图像。
需要 Word 将文档与图片连接,返回一个带有图片但文字下方各部分文字都带有相应标记的文档:可以是徽标、机密横幅或草稿标记。您可以控制图片大小(精确到磅或缩放比例)、50% 透明度切换以及居中或左上角位置。响应结果为: JSON 结果为 Base64 内容。
验证您的身份 API 要求
每一个 PDF4me REST 通话必须包含您的 API 关键在于 Authorization 请求头设置为基本身份验证。请从开发者控制面板获取或轮换您的密钥。
端点
office/ApiV2Word/添加水印您不容错过的重要事实
fileName, success, 和 错误信息请先解码再保存;原始响应不是有效的 .docx 文件。宽度/高度 先按积分计算,然后 规模然后是原始图像尺寸。只需发送一个尺寸,另一个尺寸会自动计算以保持宽高比。半透明:真 呈现出经典的淡雅印章效果。HTTP 设置
方法: POST
URL: https://api.pdf4me.com/office/ApiV2Word/AddWatermark
内容类型: application/json
Authorization: 基本 <您的 PDF4me API 键>
回答是 JSON检查 success 然后,举旗。 Base64-解码返回的文档内容并将其保存 .docx 扩大。
水印尺寸优先级是如何运作的?
共有三种尺寸输入参数,它们有严格的排序。 API 使用您实际发送的最高优先级输入,并忽略其余输入。
| 输入与行为的规模 | 适用时 | 水印会得到什么 |
|---|---|---|
width 和 height (分数) | 最高优先级;覆盖。 scale 存在 | 完全按照您指定的尺寸来。只需一个尺寸即可保持长宽比。 |
scale (0.1 至 10.0) | 仅当未发送宽度或高度信息时使用。 | 原始图像尺寸乘以一个系数:0.5 为一半尺寸,2.0 为两倍尺寸。 |
| 两人都没发信息。 | 倒退 | 上传图像的原始像素尺寸 |
API 身体场
| 范围 | 必需的 | 类型 | 它的作用 | 例子 |
|---|---|---|---|---|
document | Required | object | Document reference carrying Name, the Word filename with its .docx extension. | { "Name": "document.docx" } |
docContent | Required | string | Base64-encoded bytes of the Word document to watermark. | UEsDBBQABgAIAAAA... |
watermarkFileName | Required | string | Watermark image filename with its extension. PNG, JPG, JPEG, BMP, and GIF are supported. | watermark.png |
watermarkFileContent | Required | string | Base64-encoded bytes of the watermark image. A PNG with a transparent background gives the cleanest behind-text result. | iVBORw0KGgo... |
scale | Optional | number | Scale factor from 0.1 to 10.0 applied to the original image size. Default 1.0. Ignored when width or height is sent. | 1.5 |
semiTransparent | Optional | boolean | true renders the watermark at 50 percent opacity for a subtle stamp; false (default) keeps full opacity. | true |
width | Optional | number | Exact watermark width in points. Overrides scale. If height is omitted it is calculated to keep the aspect ratio. | 200 |
height | Optional | number | Exact watermark height in points. Overrides scale. If width is omitted it is calculated to keep the aspect ratio. | 150 |
alignImage | Optional | boolean | true (default) centers the watermark on the page; false aligns it top-left within the margins. | true |
cultureName | Optional | string | Culture code applied to document metadata during processing, for example en-US or de-DE. | en-US |
示例有效载荷
最简请求(仅需填写必填字段)
{
"document": { "Name": "document.docx" },
"docContent": "UEsDBBQABgAIAAAA...",
"watermarkFileName": "watermark.png",
"watermarkFileContent": "iVBORw0KGgoAAAANSUhEUgAA..."
}
尺寸合适,半透明,居中
{
"document": { "Name": "contract-draft.docx" },
"docContent": "UEsDBBQABgAIAAAA...",
"watermarkFileName": "confidential.png",
"watermarkFileContent": "iVBORw0KGgoAAAANSUhEUgAA...",
"width": 200,
"height": 150,
"semiTransparent": true,
"alignImage": true,
"cultureName": "en-US"
}
邮递员收款小贴士
curl 示例
curl -X POST https://api.pdf4me.com/office/ApiV2Word/AddWatermark \
-H "Content-Type: application/json" \
-H "Authorization: Basic YOUR_API_KEY" \
-d '{
"document": { "Name": "document.docx" },
"docContent": "'"$(base64 -w 0 document.docx)"'",
"watermarkFileName": "watermark.png",
"watermarkFileContent": "'"$(base64 -w 0 watermark.png)"'",
"semiTransparent": true
}' \
--output response.json
什么 API 返回?
A JSON 结果文档带有水印 Base64。
| 场地 | 类型 | 它包含什么 |
|---|---|---|
document | String (Base64) | The watermarked Word document content. Decode to bytes and save with a .docx extension. |
fileName | String | Output filename for the watermarked document. |
success | Boolean | true when watermarking succeeded. Check this before decoding content. |
errorMessage | String | Populated when success is false: invalid Base64, a corrupted document or image, or out-of-range sizing values. |
异步行为(202) Accepted 通过民意调查 URL 在 Location 请求头)由服务器配置控制,而不是由请求体参数控制。当收到 202 响应时,轮询 Location URL 和 GET 直到收到 200 个请求为止 OK 与 JSON 形状。
代码示例
Word 办公终端尚未包含在示例库中按终端创建的示例文件夹中;它承载着所有终端使用的请求模式。 PDF4me 端点系列:
常问问题
为什么要通过以下方式添加水印 API 而不是手动操作 Word?
手动路线是 在图片中插入水印 Word打开每个文件,点击“设计”选项卡,选择“水印”,然后选择“自定义水印”,选择图片,保存,重复此操作。这种方法无法扩展到需要在每个外发草稿上都添加水印的合同流程。 API 每个文件应用与一次确定性请求相同的文本后标记,并具有精确的点大小。 Word 对话框未显示。结果是标准的。 数字水印 用于溯源和状态标记,以流水线速度应用。