如何使用Google Docs API v1和Python将内联图像居中
我试图使用GoogleDocsAPI和Python将图像居中,我遵循了文档说明,建议定义一个内联图像。图像显示在生成的文档中,但不在文档的中心。 有没有办法使图像居中? 这是我的密码:如何使用Google Docs API v1和Python将内联图像居中,python,google-docs-api,Python,Google Docs Api,我试图使用GoogleDocsAPI和Python将图像居中,我遵循了文档说明,建议定义一个内联图像。图像显示在生成的文档中,但不在文档的中心。 有没有办法使图像居中? 这是我的密码: requests = [ { 'replaceAllText': { 'containsText': { 'text': '{{ customer.name }}', 'matchCas
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')
谢谢- 您希望使用Google Docs API将内联图像插入文档中心
- 您已经将Google Docs API与用于Python的Google客户端库一起使用过
- 为了使图像与中心对齐,使用了
updateParagraphStyle
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"
}
}
]
参考:
- 您希望使用Google Docs API将内联图像插入文档中心
- 您已经将Google Docs API与用于Python的Google客户端库一起使用过
- 为了使图像与中心对齐,使用了
updateParagraphStyle
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"
}
}
]
参考:
如果这不是您想要的结果,我很抱歉。我的回答是否显示了您想要的结果?你能告诉我这件事吗?这对我的学习也很有用。如果这样做有效,其他与你有相同问题的人也可以将你的问题作为可以解决的问题。如果你对我的回答还有疑问,我道歉。那时候,我可以问一下你目前的情况吗?我想研究解决你的问题。谢谢你的回复。我很高兴你的问题解决了。也谢谢你。我的回答告诉你结果了吗?你能告诉我这件事吗?这对我的学习也很有用。如果这样做有效,其他与你有相同问题的人也可以将你的问题作为可以解决的问题。如果你对我的回答还有疑问,我道歉。那时候,我可以问一下你目前的情况吗?我想研究解决你的问题。谢谢你的回复。我很高兴你的问题解决了。也谢谢你。