I'm trying to center an image using Google Docs API and Python, i followed the documention which suggests to define an inline image. The image is shown in the generated document but is not in the center of the document. Is there any way to center the image? Here is my code:
requests = [
{
'replaceAllText': {
'containsText': {
'text': '{{ customer.name }}',
'matchCase': 'true'
},
'replaceText': context['customer'],
}},
{
'insertInlineImage': {
'location': {
'index': 55
},
'uri':
'https://www.gstatic.com/images/branding/product/1x/docs_64dp.png',
'objectSize': {
'height': {
'magnitude': 50,
'unit': 'PT'
},
'width': {
'magnitude': 50,
'unit': 'PT'
}
}
}
}
]
risk_assessment_customer = drive_service.files().copy(fileId=DOCUMENT_ID, body={}).execute()
result = service.documents().batchUpdate(
documentId=risk_assessment_customer['id'], body={'requests': requests}).execute()
request = drive_service.files().export_media(fileId=result['documentId'],
mimeType='application/pdf')
Thank you
If my understanding is correct, how about this modification? In this modification, I modified your request body.
updateParagraphStyle
is used.Please replace the request body as follows.
requests = [
{
'replaceAllText': {
'containsText': {
'text': '{{ customer.name }}',
'matchCase': 'true'
},
'replaceText': context['customer'],
}
},
{
"insertInlineImage": {
"location": {
"index": 55
},
"uri": "https://www.gstatic.com/images/branding/product/1x/docs_64dp.png",
"objectSize": {
"height": {
"magnitude": 50,
"unit": "PT"
},
"width": {
"magnitude": 50,
"unit": "PT"
}
}
}
},
{
"updateParagraphStyle": {
"range": {
"startIndex": 55,
"endIndex": 56
},
"paragraphStyle": {
"alignment": "CENTER"
},
"fields": "alignment"
}
}
]
If this was not the result you want, I apologize.