10

ユーザーの操作なしでGoogleドライブAPIを使用してHTMLファイルをアップロードしてPDFに変換することは可能ですか?

4

2 に答える 2

11

はい、そうです、2つのリクエストがあります。ファイルをGoogleドキュメントとしてインポートしてから、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 に答える