Code sample for add/barcode
API
Python
This Python sample demonstrates how to access the PDFTeam add/barcode
API endpoint. The sample takes an existing PDF and adds two barcodes: A QR code is positioned in the lower left, a Code 128 in the middle left. Both codes are created without text line, the Code 128 barcode is rotated 90 degrees. 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/barcode
import requests
import json
url = 'https://api.pdfteam.com/api/add/barcode'
payload = {
"job":"00012345",
"user":"YOUR_USERNAME",
"key":"YOUR_APIKEY",
"test":True,
"inputOptions":{
"source": "https://pdfteam.com/samples/invoice.pdf"
},
"outputOptions":{
"storage":True,
"file":"barcode_invoice.pdf"
},
"overlays":[
{
"position":{
"x":"18mm",
"y":"25mm"
},
"type":"barcode",
"config":{
"type":19,
"data":"https://pdfteam.com"
}
},
{
"rotate": 90,
"position":{
"x":"15mm",
"y":"middle"
},
"type":"barcode",
"config":{
"humanReadableText":False,
"moduleHeight": 10,
"type":7,
"data":"00012345"
}
}
]
}
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/barcode', 'job': '00012345', 'credits': 1, 'result': 'https://pdfteam.s3.eu-north-1.amazonaws.com/.../barcode_invoice.pdf'}
Sample result: