Home

Existing customer? Sign In

Guide: Stamp PDFs with an API Request

Published on: Apr, 15 2022

This tutorial will show you how to stamp PDFs with an API request. PDFs stamped with personal information such as name, email address, or phone number are much less likely to be distributed without your permission.

Other reasons for PDF stamping include:

In our example, we will add a small logo and the customer's email address to the bottom of every page of the PDF document. Here's how it will look:

Stamp PDF API For testing purposes we will make the API request with Insomnia API client. It's a great API client! You can download it for free here.

Prerequisites

  1. You must have a Docamatic account. Docamatic free plan allows 30 documents per month. You can create an account here .

  2. To make test API requests you will need an API client like Insomnia or Postman.

Overview

Here is orginal PDF document that we will be stamping. To stamp the PDF we will make a simple API request to Docamatic's /write endpoint.

The endpoint expects you to provide a source PDF document (the PDF to be stamped) either as a URL or base64 encoded PDF.

To position each element on the PDF, you need to specify its XY coordinates. For text elements, it is possible to perform some basic styling (bold, text, underline) and font size. Please check out the write endpoint docs for further details.

Making the API request with Insomnia API Client

  1. Open the Insomnia API client and create a new Design Document.

  2. Click on the Debug tab and create a New Request by clicking on the + icon. Stamp PDF API

  3. Give the request a meaningful name "Stamp PDF", select POST from the drop down list, then click Create. Stamp PDF API

  4. Paste in the write endpoint URL: https://docamatic.com/api/v1/write and then click on the Headers tab. Add two headers, "Accept" and "Content Type" with values of "application/json". Stamp PDF API

  5. Select Bearer as the authentication method. Log into the Docamatic dashboard and grab your API key, then paste it into Insomnia. Stamp PDF API

  6. Copy the JSON below. We are passing 3 parameters in our API request:

    • source (URL to PDF or base64 encoded PDF)
    • text (an array of text elements to add to the PDF, positioned by XY coordinates)
    • images (an array of images to add to the PDF, positioned by XY coordinates)
{
	"source": "https://docamatic.s3.eu-west-1.amazonaws.com/blog/stamp.pdf",
	"text": [
		{
			"text_value": "Sold to",
			"text_color": "#b9b9b9",
			"font_size": 10,
			"font_style": "B",
			"text_x": 36,
			"text_y": 266
		},
		{
			"text_value": "customer@test.com",
			"text_color": "#b9b9b9",
			"font_size": 9,
			"text_x": 36,
			"text_y": 269
		}
	],
	"images": [
		{
			"image_url": "https://docamatic.com/apple-touch-icon.png",
			"image_width": "8",
			"image_height": "8",
			"image_x": 25,
			"image_y": 262
		}
	]
}
  1. Paste the JSON into Insomnia, then click Send to make the API request.

Stamp PDF API If the request was successful, you should receive a 200 OK response. Log into the Docamatic dashboard to download the resulting document. That's it!

Return to blog