我通过 Google Drive 服务将 HTML 文件转换为 PDF。我想在页面上添加页眉和页脚。如何使用 Java Google Drive API 做到这一点?
PS:如果没有正确的方法,我们将不胜感激。
最佳答案
我认为您无法直接使用 Google Drive API 来执行此操作。如果您可以使用一些解决方法,我会使用 Google Apps Script FooterSection Class :
- 使用 Files.insert() 上传文件使用选项convert=true
- 在特定文件夹上触发或继续运行脚本,执行以下操作:
- 使用 FooterSection Class 修改页脚
- 将 Google 文档文件导出为 PDF
为了导出PDF,我能想到的有两种方法。
使用Document Class Apps 脚本的数量
doc.getAs("application/pdf")
或者使用 Files.list() 从 Google Drive API 获取 PDF 的导出链接您可以在其中获取 PDF 的下载链接。
"exportLinks": {
"application/pdf": "https://docs.google.com/feeds/download/spreadsheets/Export?key={FILE_KEY}&exportFormat=pdf",
"application/x-vnd.oasis.opendocument.spreadsheet": "https://docs.google.com/feeds/download/spreadsheets/Export?key={FILE_KEY}&exportFormat=ods",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "https://docs.google.com/feeds/download/spreadsheets/Export?key={FILE_KEY}&exportFormat=xlsx"
},
关于java - 如何从 Java API 在 Google Drive 中添加页眉/页脚?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16898202/