【问题标题】:HTML2PDF using Google Drive API使用 Google Drive API 的 HTML2PDF
【发布时间】:2012-10-02 08:59:24
【问题描述】:

是否可以在没有user interaction 的情况下使用 Google Drive API 上传 HTML 文件并将其转换为 PDF?

【问题讨论】:

  • 你尝试了什么?你搜索了吗?您是否阅读过 API 文档?
  • @Jocelyn Proppy 在 Google 工作,所以我大胆猜测一下,他可能在发帖前尝试了明显的东西。
  • @NickJohnson 好吧,我们不是巫师,我们应该怎么猜?每个在 Stackoverflow 上发布问题的人都应该展示他尝试过的内容,以及他已经搜索过的内容。
  • @Jocelyn 从文档developers.google.com/drive/… 中并不明显,这可以在没有任何用户交互的情况下完成。我更新了我的问题,并会记得说明我已经为将来的问题所做的研究。
  • @Jocelyn 一种选择是点击他的名字并阅读他的个人资料描述,其中指出“App Engine 开发人员计划工程师,驻苏黎世,是 Google 开发人员关系团队的一员”。

标签: html pdf google-drive-api


【解决方案1】:

是的,有两个请求。您可以将文件作为 Google Docs 导入,然后将其导出为 PDF。使用 Drive API。

https://developers.google.com/drive/v2/reference/files/insert https://developers.google.com/drive/v2/reference/files/get

【讨论】:

  • 是否也可以将 docx 转换为 pdf 然后下载?
【解决方案2】:

为我工作(仅限云端硬盘文档...)

ByteArrayContent mediaContent = new ByteArrayContent("text/html", "HTML PAGE HERE".getBytes());

File body = new File();
body.setTitle("test.html");
body.setMimeType("text/html");

Insert request = null;
try
{
   request = service.files().insert(body, mediaContent);
   request.setConvert(true);
   File file = request.execute();

   HttpResponse resp = service.getRequestFactory().buildGetRequest(new    GenericUrl(file.getExportLinks().get("application/pdf"))).execute();

   OutputStream out = new FileOutputStream(getExternalFilesDir(null).getAbsolutePath() + "/test.pdf");
   byte[] buf = new byte[1024];
   int len;
   while ((len = resp.getContent().read(buf)) > 0)
    {
        out.write(buf, 0, len);
    }
    out.close();

}
catch (IOException e)
{
    e.printStackTrace();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多