java - 如何从 Java API 在 Google Drive 中添加页眉/页脚?

标签 java pdf-generation google-drive-api

我通过 Google Drive 服务将 HTML 文件转换为 PDF。我想在页面上添加页眉和页脚。如何使用 Java Google Drive API 做到这一点?

PS:如果没有正确的方法,我们将不胜感激。

最佳答案

我认为您无法直接使用 Google Drive API 来执行此操作。如果您可以使用一些解决方法,我会使用 Google Apps Script FooterSection Class :

  1. 使用 Files.insert() 上传文件使用选项convert=true
  2. 在特定文件夹上触发或继续运行脚本,执行以下操作:
  3. 使用 FooterSection Class 修改页脚
  4. 将 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/

相关文章:

java - 返回 boolean 变量或返回条件都相同吗?

android - 从哪里获得 Drive API v2 和依赖项的 Android 库(首选 Maven)?

google-api - 如何在 Dart 中的 Google Drive GoogleAPIs v3 中设置 `fields` 参数?

asp.net - 无需使用 Office 自动化即可将 Office 文档转换为 PDF 的开源解决方案

ios - 将图像上传到 Google 云端硬盘公共(public)文件夹

java - 由于 Java 的跨平台能力,Java 中的开销是否比 C# 更多?

java - 错误注入(inject) : org. jboss.as.plugin.deployment.Deploy

java - 如何使用 apache poi 检查 xlsx 文件是否受密码保护

c# - 使用 iTextSharp 在 PdfPCell 中自动调整图像大小

pdf - 您将如何以编程方式在 PDF 中嵌入 SWF?