简体   繁体   English

如何通过Java API在Google云端硬盘中添加页眉/页脚?

[英]How to add Header/Footer in Google Drive from Java API?

I converting HTML file to PDF via Google Drive Service. 我通过Google云端硬盘服务将HTML文件转换为PDF。 I want to add Header and Footer on pages. 我想在页面上添加页眉和页脚。 How can do that using Java Google Drive API? 如何使用Java Google Drive API做到这一点?

PS: If there is not proper way than any workaround would be appreciated. PS:如果没有正确的方法,那么不采取任何解决方法。

I don't think you can do this directly using Google Drive API. 我认为您不能直接使用Google Drive API来执行此操作。 If you are fine with some workaround, I would use Google Apps Script FooterSection Class : 如果您有一些解决方法,我可以使用Google Apps脚本FooterSection类

  1. Upload file using Files.insert() with option convert=true 使用Files.insert()使用选项convert = true上传文件
  2. Either trigger or keep running script on specific folder which does the following: 在特定文件夹上执行以下操作的触发器或保持运行脚本:
  3. Modify Footer using FooterSection Class 使用FooterSection类修改页脚
  4. Export Google Document file as PDF 将Google文档文件导出为PDF

In order to export PDF, there are two ways I can think of. 为了导出PDF,我可以想到两种方法。

Using Document Class of Apps script 使用Apps的文档类脚本

doc.getAs("application/pdf") 

Or getting export link of PDF from Google Drive API using Files.list() where you can get downloadable link for 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"
   },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM