跳到主要内容

添加水印 Word

PDF4me 添加水印 Word 是一个 REST 该端点会在每一页的文本后面添加图像水印。 Word 文档。 POST .docx 文件和水印图像 Base64office/ApiV2Word/AddWatermark调整缩放比例、透明度和对齐方式,然后解码带有水印的文件。 JSON 回复。 PNGJPGJPEG支持 BMP 和 GIF 图像。

此端点的作用

需要 Word 将文档与图片连接,返回一个带有图片但文字下方各部分文字都带有相应标记的文档:可以是徽标、机密横幅或草稿标记。您可以控制图片大小(精确到磅或缩放比例)、50% 透明度切换以及居中或左上角位置。响应结果为: JSON 结果为 Base64 内容。

相关博客文章
目前尚无关于此功能的博客文章——敬请期待。
在此期间,您可以浏览 PDF4me 博客,查看适用于各平台的教程和工作流程。
访问博客

验证您的身份 API 要求

每一个 PDF4me REST 通话必须包含您的 API 关键在于 Authorization 请求头设置为基本身份验证。请从开发者控制面板获取或轮换您的密钥。

端点

POSToffice/ApiV2Word/添加水印

您不容错过的重要事实

回答是 Base64 JSON不是文件
带有水印的文档以以下形式返回: Base64 字符串内部 JSON 身体 fileNamesuccess, 和 错误信息请先解码再保存;原始响应不是有效的 .docx 文件。
宽度和高度会覆盖缩放比例。
尺寸优先级为精确 宽度/高度 先按积分计算,然后 规模然后是原始图像尺寸。只需发送一个尺寸,另一个尺寸会自动计算以保持宽高比。
文本背后,在每个部分
图像以透明方式叠加在文档内容下方,覆盖所有章节和标题,因此文本仍然清晰可读。 PNG半透明:真 呈现出经典的淡雅印章效果。

HTTP 设置

方法: POST
URL https://api.pdf4me.com/office/ApiV2Word/AddWatermark
内容类型: application/json
Authorization 基本 <您的 PDF4me API 键>

回答是 JSON检查 success 然后,举旗。 Base64-解码返回的文档内容并将其保存 .docx 扩大。

水印尺寸优先级是如何运作的?

共有三种尺寸输入参数,它们有严格的排序。 API 使用您实际发送的最高优先级输入,并忽略其余输入。

输入与行为的规模适用时水印会得到什么
widthheight (分数)最高优先级;覆盖。 scale 存在完全按照您指定的尺寸来。只需一个尺寸即可保持长宽比。
scale (0.1 至 10.0)仅当未发送宽度或高度信息时使用。原始图像尺寸乘以一个系数:0.5 为一半尺寸,2.0 为两倍尺寸。
两人都没发信息。倒退上传图像的原始像素尺寸

API 身体场

范围必需的类型它的作用例子
documentRequiredobjectDocument reference carrying Name, the Word filename with its .docx extension.{ "Name": "document.docx" }
docContentRequiredstringBase64-encoded bytes of the Word document to watermark.UEsDBBQABgAIAAAA...
watermarkFileNameRequiredstringWatermark image filename with its extension. PNG, JPG, JPEG, BMP, and GIF are supported.watermark.png
watermarkFileContentRequiredstringBase64-encoded bytes of the watermark image. A PNG with a transparent background gives the cleanest behind-text result.iVBORw0KGgo...
scaleOptionalnumberScale 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
semiTransparentOptionalbooleantrue renders the watermark at 50 percent opacity for a subtle stamp; false (default) keeps full opacity.true
widthOptionalnumberExact watermark width in points. Overrides scale. If height is omitted it is calculated to keep the aspect ratio.200
heightOptionalnumberExact watermark height in points. Overrides scale. If width is omitted it is calculated to keep the aspect ratio.150
alignImageOptionalbooleantrue (default) centers the watermark on the page; false aligns it top-left within the margins.true
cultureNameOptionalstringCulture 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"
}

邮递员收款小贴士

Headers
Content-Type: application/json + Authorization: Basic <apiKey>.
Body
raw JSON with TWO Base64 fields: docContent for the Word file and watermarkFileContent for the image. Both must be encoded separately.
Sizing
Send width/height OR scale, not both. If you send both, the exact dimensions win and scale is silently ignored.
Response
JSON with a success flag and Base64 document content. Decode the document field before saving as .docx.

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

场地类型它包含什么
documentString (Base64)The watermarked Word document content. Decode to bytes and save with a .docx extension.
fileNameStringOutput filename for the watermarked document.
successBooleantrue when watermarking succeeded. Check this before decoding content.
errorMessageStringPopulated when success is false: invalid Base64, a corrupted document or image, or out-of-range sizing values.

异步行为(202) Accepted 通过民意调查 URLLocation 请求头)由服务器配置控制,而不是由请求体参数控制。当收到 202 响应时,轮询 Location URLGET 直到收到 200 个请求为止 OKJSON 形状。

代码示例

Word 办公终端尚未包含在示例库中按终端创建的示例文件夹中;它承载着所有终端使用的请求模式。 PDF4me 端点系列:

常问问题

Which image formats can I use as a Word watermark?+
PNG, JPG, JPEG, BMP, and GIF. A PNG with a transparent background gives the cleanest result because the image is stamped behind the document text on every page.
Is the response the Word file itself?+
No. The API returns JSON containing the watermarked document as a Base64 string plus fileName, success, and errorMessage fields. Decode the document field to bytes before saving as .docx.
What happens if I send both scale and width or height?+
Width and height win. Exact dimensions in points always override the scale factor. If you provide only one of the two, the other is calculated automatically to preserve the image aspect ratio.
Does the watermark cover the document text?+
No. The watermark is placed behind the text, in every section of the document, so the content stays readable. Set semiTransparent to true for a subtle 50 percent opacity effect.
Can this endpoint add text watermarks like DRAFT or CONFIDENTIAL?+
This endpoint stamps images. For text stamps use the Add Text Watermark to Word endpoint, or render your text as a transparent PNG and pass it here as the watermark image.
Where does the watermark appear in the document?+
Across all sections and their headers, behind the content. alignImage true centers it on the page; false places it top-left within the margins. Per-page or per-range placement is not part of this action.
Does adding a watermark protect the document from editing?+
No. A watermark is a visual marker, not a security control; anyone who can edit the file can remove it. To restrict editing or require a password, chain the Secure Word Document endpoint after this one.

为什么要通过以下方式添加水印 API 而不是手动操作 Word

手动路线是 在图片中插入水印 Word打开每个文件,点击“设计”选项卡,选择“水印”,然后选择“自定义水印”,选择图片,保存,重复此操作。这种方法无法扩展到需要在每个外发草稿上都添加水印的合同流程。 API 每个文件应用与一次确定性请求相同的文本后标记,并具有精确的点大小。 Word 对话框未显示。结果是标准的。 数字水印 用于溯源和状态标记,以流水线速度应用。

相关行动

在其他平台上执行相同的任务

获取帮助