Replace Text with Image
Image → Replace Text with Image
The Replace Text with Image API replaces specified text in a PDF with an image. You send the PDF (docContent, docName), replaceText, imageContent (Base64), and optionally pageSequence (e.g. "all", "1", "2-5"), imageHeight, imageWidth, and async. The API returns the PDF with text replaced by the image. Use the tester below to try it; more details are in the sections that follow.
Try the Replace Text with Image API
Endpoint: POST /api/v2/ReplaceTextWithImage · Required: api-key, docContent, docName, replaceText, imageContent
Use the form below to send your API key, PDF (Base64), text to replace, replacement image (Base64), and optional page selection. The response is the PDF with text replaced by the image. No code required—fill the fields and click Send request.
Overview, parameters, and use cases
- Overview
- Parameters
- Use cases
What is Replace Text with Image?
This endpoint replaces specified text in a PDF with an image. You provide the PDF (Base64), docName, replaceText (the text to find), imageContent (replacement image, Base64), and optionally pageSequence ("all", "1", "1,3,5", "2-5", "2-"), imageHeight, imageWidth. The API returns the PDF with matching text replaced by the image on the selected pages.
Key features
- Text match – Replaces occurrences of replaceText with the image.
- Page selection – pageSequence: "all", "1", "1,3,5", "2-5", "2-".
- Image size – Optional imageHeight and imageWidth in points.
Use when you need to swap placeholders or text with logos, stamps, or graphics in a PDF. For adding an image without replacing text use Add Image Stamp to PDF.
API parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| api-key | string | Yes | Your PDF4me API key, Base64 encoded. Get it from the dashboard. |
| docContent | base64 | Yes | PDF file content (Base64). |
| docName | string | Yes | Output PDF file name. |
| replaceText | string | Yes | Text to be replaced with the image. |
| imageContent | base64 | Yes | Replacement image (Base64). Supported: JPG, PNG, GIF, BMP, TIFF. |
| pageSequence | string | No | Page selection: "all", "1", "1,3,5", "2-5", "2-". |
| imageHeight, imageWidth | integer | No | Height and width of the image in points. |
| async | boolean | No | Enable asynchronous processing. |
When to use Replace Text with Image
- Logos – Replace a placeholder like "[LOGO]" with a logo image.
- Stamps – Replace text with an "Approved" or "Confidential" image.
- Templates – Fill PDF templates by replacing placeholders with images.
For request/response schemas and code samples, see Image Stamp in the PDF4me API docs.
Prerequisites
Before using this endpoint, make sure you have:
- A valid PDF4me API key (Get your API Key)
- A PDF file in Base64 format
- An image file (JPG, PNG, GIF, BMP, TIFF) in Base64 format
Response Format
The API returns a PDF file with the specified text replaced by the image on the selected pages.