我正在使用驱动器中存在的模板ppt动态生成Google幻灯片。我需要将此新创建的ppt转换为图像,并将其存储在驱动器本身的另一个文件夹中。我可能在演示文稿中有多个幻灯片。
from google.oauth2 import service_account
import googleapiclient.discovery
SCOPES = (
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/presentations',
)
SERVICE_ACCOUNT_FILE = 'cred.json'
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
SLIDES = discovery.build('slides', 'v1', credentials=credentials)
DRIVE = discovery.build('drive', 'v3', credentials=credentials)
TMPLFILE = 'title slide template'
rsp = DRIVE.files().list(q="name='%s'" % TMPLFILE).execute().get('files')[0]
print(rsp)
DATA = {'name': 'Google Slides API template DEMO', 'parents': ['id_of_the_folder_for_storing_new_ppt']}
print('** Copying template %r as %r' % (rsp['name'], DATA['name']))
DECK_ID = DRIVE.files().copy(body=DATA, fileId=rsp['id']).execute().get('id')
print(DECK_ID)
print('** Replacing placeholder text')
reqs = [
{'replaceAllText': {
'containsText': {'text': '{{text}}'},
'replaceText': final_til[0]
}},
]
SLIDES.presentations().batchUpdate(body={'requests': reqs},
presentationId=DECK_ID).execute()
### till this point I was creating a new ppt
### now I need to save it as an image file
print('DONE')
通过指定
presentationId
slidesId
您要导出的幻灯片mimeType
出口-例如 PNG
thumbnailSize
-具有所需图像质量该请求将返回您的contentURL
类型https://lh3.googleusercontent.com/XXXXXXXXXXXXXXXXXX=s1600"
,您可以使用该类型在浏览器中以图片的形式查看幻灯片,或从中创建云端硬盘中的文件。
边注:
如果要导出整个演示文稿而不是一张幻灯片,请使用“文件:导出”。但是,此方法仅允许您仅将演示文稿导出为PDF,而不能导出为PNG(至少不能直接导出)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句