透かしを追加 Word
PDF4me 透かしを追加 Word は REST ページのテキストの背後に画像透かしをスタンプするエンドポイント Word 書類。 POST .docxファイルと透かし画像 Base64 に office/ApiV2Word/AddWatermarkスケール、透明度、配置を調整し、透かし入りのファイルをデコードします。 JSON 応答。 PNG、 JPG、 JPEGBMPおよびGIF画像がサポートされています。
取る Word ドキュメントに画像を追加し、その画像が各セクションのテキストの背後にスタンプされた同じドキュメントを返します。ロゴ、機密バナー、下書きスタンプなどです。サイズ(正確なポイントまたは拡大縮小率)、50%の透明度の切り替え、中央または左上の配置を制御できます。応答は JSON 結果として Base64 コンテンツ。
認証 API リクエスト
毎 PDF4me REST 電話にはあなたの API キー Authorization ヘッダーを基本認証として設定します。開発者ダッシュボードからキーを取得またはローテーションしてください。
終点
office/ApiV2Word/AddWatermark見逃してはならない重要な事実
fileName、 success、 そして エラーメッセージ保存する前にデコードしてください。生のレスポンスは有効な .docx ファイルではありません。幅/身長 まずポイントで、次に 規模すると、元の画像サイズが返されます。1つの寸法だけを送信すると、もう1つの寸法は縦横比を維持するように計算されます。半透明: true クラシックでさりげないスタンプのような印象を与えます。HTTP 設定
方法: POST
URL: https://api.pdf4me.com/office/ApiV2Word/AddWatermark
コンテンツタイプ: アプリケーション/json
Authorization: 基本 <あなたの PDF4me API キー>
回答は JSON: チェック success フラグを立てて、それから Base64-返されたドキュメントの内容をデコードして保存します .docx 拡大。
透かしのサイズ設定における優先順位はどのように機能するのですか?
サイズ決定の入力項目は3つあり、厳密に順位付けされています。 API 実際に送信された入力の中で最も優先度の高いものを使用し、それ以外は無視します。
| 入力サイズと動作の比較 | 該当する場合 | 透かしが得るもの |
|---|---|---|
width そして height (ポイント) | 最優先; 上書き scale 存在する場合 | 指定した寸法と全く同じです。1つの寸法だけでアスペクト比が維持されます。 |
scale (0.1~10.0) | 幅または高さが送信されない場合にのみ使用されます。 | 元の画像サイズに係数を乗じた値:0.5は半分のサイズ、2.0は2倍のサイズ |
| どちらも送信しなかった | 後退する | アップロードされた画像の元のピクセル寸法 |
API ボディフィールド
| パラメータ | 必須 | その機能 | 例 |
|---|---|---|---|
| document | Required | Source file. `Name` must end in `.docx` or `.doc`. | { "Name": "document.docx" } |
| document.Name | Required | File name including its extension. Type: string. | { "Name": "document.docx" } |
| docContent | Required | The source file, base64-encoded. Type: string. | UEsDBBQABgAIAAAA... |
| isAsync | Optional | Process the request in the background. The call returns `202 Accepted`; poll the `Location` URL (`GetActionStatus`) for the result. Type: boolean. | |
| watermarkFileContent | Required | The image, base64-encoded. Type: string. | iVBORw0KGgo... |
| watermarkFileName | Optional | The image file name. Type: string. | watermark.png |
| width | Optional | Image width in points. If only one of `width`/`height` is set, the other keeps the image's proportions. Type: number. | 200 |
| height | Optional | Image height in points. Type: number. | 150 |
| scale | Optional | Resize factor, used only when `width` and `height` are not set. Type: number. | 1.5 |
| semiTransparent | Optional | Show the image at 50% opacity. Type: boolean. | true |
| alignImage | Optional | `true` centers the image; `false` places it at the top-left. Type: boolean. | true |
サンプルペイロード
必要最低限のリクエスト(必須項目のみ)
{
"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 ファイルごとに 1 つの決定論的リクエストとして同じテキストの背後のスタンプを適用し、正確なポイントサイズで Word ダイアログは公開しません。結果は標準です デジタル透かし 出所およびステータス表示のために、パイプラインの速度で適用されます。