10

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

4

2 回答 2

11

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

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

于 2012-10-11T16:12:17.790 回答
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();
}
于 2014-02-11T19:22:39.573 回答