Code Sample for html/2/pdf
API
Python
This Python sample demonstrates how to access the PDFTeam html/2/pdf
API endpoint. The sample converts an HTML invoice to a PDF and adds overlays with some text, a company logo and a QR code. 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: html/2/pdf
import requests
import json
url = 'https://api.pdfteam.com/api/html/2/pdf'
payload = {
"job":"00012345",
"user":"YOUR_USERNAME",
"key":"YOUR_APIKEY",
"test":True,
"inputOptions":{
"source": "https://pdfteam.com/samples/invoice.html"
},
"outputOptions":{
"storage":True,
"file":"converted_invoice.pdf"
},
"pdfOptions":{
"format":"Letter"
},
"overlays":[
{
"position":{
"x":"left",
"y":"30mm"
},
"type":"barcode",
"config":{
"type":19,
"data":"https://pdfteam.com"
}
},
{
"rotate":45,
"position":{
"x":"center",
"y":"middle"
},
"type":"text",
"config":{
"data":"PAST DUE",
"font":"Helvetica Bold",
"size":72,
"color":"#ff0000",
"opacity":0.5
}
},
{
"position":{
"x":"132mm",
"y":"228mm"
},
"type":"image",
"config":{
"source":"https://pdfteam.com/samples/acme_logo.png"
}
}
]
}
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': 'html/2/pdf', 'job': '00012345', 'credits': 1, 'result': 'https://pdfteam.s3.eu-north-1.amazonaws.com/.../acme_invoice.pdf'}
Sample result: