Code sample for add/text API

Python


This Python sample demonstrates how to access the PDFTeam add/text API endpoint. The sample takes an existing PDF and adds two text overlays: a text 'TOP SECRET' in red, centered on the page and rotated 45 degrees and an informational header near the top of the page in blue. The resulting PDF will be stored in AWS S3, the permalink is returned to the caller.

Setting "test" to True will not consume any credits but the generated PDF carries a watermark.


This sample is also available as a Colab notebook.

# Sample code for accessing the PDFTeam API, endpoint: add/text

import requests
import json

url = 'https://api.pdfteam.com/api/add/text'

payload = {
  "job":"00012345",
  "user":"YOUR_USERNAME",
  "key":"YOUR_APIKEY",
  "test":True,
  "inputOptions":{
    "source": "https://pdfteam.com/samples/coyote_report.pdf"
  },
  "outputOptions":{
    "storage":True,
    "file":"processed_report.pdf"
  },
  "overlays":[
    {
      "rotate": 45,
      "position": {
        "x": "center",
        "y": "middle",
      },
      "firstPageOnly": False,
      "type": "text",
      "config": {
        "data": "TOP SECRET",
        "font": "Helvetica Bold",
        "size": 72,
        "color": "#ff0000",
        "opacity": 0.5,
      },
    },
    {
      "position": {
        "x": "center",
        "y": "270mm",
      },
      "firstPageOnly": False,
      "type": "text",
      "config": {
        "data": "Send comments and suggestions to fatalon@coyoteduty.com. Deadline is April, 10.",
        "font": "Helvetica Bold",
        "size": 12,
        "color": "#0000FF",
      },
    }
  ]
}

headers = {
  'content-type': 'application/json'
}

response = requests.request('POST', url, data=json.dumps(payload), headers=headers)

if response.status_code == 200:
  result = json.loads(response.text)
  print(result)
else:
  print('Error: ' + response.text)


Sample return:

{'endpoint': 'add/text', 'job': '00012345', 'credits': 1, 'result': 'https://pdfteam.s3.eu-north-1.amazonaws.com/.../processed_report.pdf'}


Sample result:

PDF with multiple text overlays created with Python