Stamp text in PDF.

Add text stamps on PDFs through the Pdftools API. A text stamp annotation displays text intended to look as if it was stamped on the page with a rubber stamp. You can determine the text of the stamp, the appearance (font family, style, and color), and the position on the page.

1. Authenticate API calls.

Include the header X-Api-Key to properly authorize your API calls.

  • Name
    X-Api-Key
    Type
    string
    Type
    Optional
    Description

    Substitute <API-KEY-VALUE> with the value of your API key.

X-Api-Key: <API-KEY-VALUE>

2. Get upload URL.

Send the following API call to get the upload URL.

  • Name
    X-Api-Key
    Type
    string
    Type
    Optional
    Description

    Header containing your API key.

  • Name
    fileName
    Type
    string
    Type
    Optional
    Description

    The name of the file that we are going to be uploading. ex input.pdf input.png ...

Learn more about ways to upload files on the API Reference

POST
/v1/files/upload/fromLocal
curl -L -X POST 'https://api.pdf-tools.com/v1/files/upload/fromLocal' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'X-Api-Key: <API_KEY_VALUE>' \
--data-raw '{
"fileName": "input.pdf"
}' 

Response

{
    "fileId": "101be847-f838-4361-9e27-27030291a329",
    "uploadUrl": "https://pdftools-production-developer-plat..."
}

3. Upload local file.

Upload a file to a URL. You received the URL as an uploadUrl in the response of the call described in the previous section.

  • Name
    UPLOAD_URL
    Type
    string
    Type
    Optional
    Description

    uploadUrl from previous step response.

  • Name
    PATH_TO_LOCAL_FILE
    Type
    string
    Type
    Optional
    Description

    System path to the file you want to upload, ex: c:\input.pdf c:\input.png ...

If the API call is successful, you receive the HTTP 200 status code.

PUT
<UPLOAD_URL>
curl --location --request PUT '<UPLOAD_URL>' \
--header 'Content-Type: application/octet-stream' \
--data '@<PATH_TO_LOCAL_FILE>'

4. Stamp text in PDF.

Run the stamping operation.

  • Name
    FILE_ID
    Type
    string
    Type
    Optional
    Description

    The fileId received in the response of the upload call.

Learn more about this operation on the API Reference

POST
/v1/operations/stamp/text
curl -L -X POST 'https://api.pdf-tools.com/v1/operations/stamp/text' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'X-Api-Key: <API_KEY_VALUE>' \
--data-raw '{
    "input": {
        "fileId": "<FILE_ID>"
    },
    "options": {
        "margin": {
        "top": 1.0,
        "right": 1.0,
        "unit": "in"
        },
        "text": "pdf-tools"
        "textStyle": {
            "textColor": "black",
            "fontFamily": "serif",
            "isBold": false,
            "isItalic": false,
            "fontSize": 12
        }
    }
}'

Response

{
"operationId": "f8418394-73f1-4ad4-8bb2-cda3ad9ff785",
"operationType": "stampText",
"operationStatus": "inProgress"
}

5. Get the result.

In order to get the result, you have to use the operationId from the previous response, in this endpoint.

  • Name
    API_KEY_VALUE
    Type
    string
    Type
    Optional
    Description

    Header containing your API key from step 1

  • Name
    OPERATION_ID
    Type
    string
    Type
    Optional
    Description

    The operationId from the result in step 4.

Once the operation is done processing you will be able to download the result file from outputFile.url property of the resulting object.

GET
/v1/operations/<OPERATION_ID>/result
curl -L -X GET 'https://api.pdf-tools.com/v1/operations/<OPERATION_ID>/result' \
-H 'Accept: application/json' \
-H 'X-Api-Key: <API_KEY_VALUE>'

Response

{
    "operationType": "stampText",
    "operationStatus": "finished",
    "outputFile": {
    "fileId": "532e9577-e943-4957-9d67-d3f04b128978",
    "name": "output.pdf",
    "url": "www.exampleurl/output.pdf"
}

Was this page helpful?