Có thể tải lên và chuyển đổi tệp HTML sang PDF bằng API Google Drive mà không cần user interaction không?HTML2PDF bằng API Google Drive
8
A
Trả lời
8
Có, đó là, với hai yêu cầu. Bạn có thể nhập tệp dưới dạng Google Tài liệu, sau đó xuất tệp sang PDF. Sử dụng API Drive.
https://developers.google.com/drive/v2/reference/files/insert https://developers.google.com/drive/v2/reference/files/get
+1
Và nó cũng sẽ có thể chuyển đổi cho phép nói một docx để pdf và sau đó tải về nó? – Rvanlaak
2
làm việc cho tôi (Drive chỉ tài liệu ...)
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();
}
bạn đã thử làm gì? Bạn đã tìm kiếm chưa? Bạn đã đọc tài liệu API chưa? – Jocelyn
@Jocelyn Proppy hoạt động tại Google, vì vậy tôi sẽ đoán một cách hoang dã và nói rằng anh ấy có thể đã thử những nội dung hiển nhiên trước khi đăng. –
@NickJohnson Vâng, chúng tôi không phải là pháp sư, chúng ta phải đoán điều đó như thế nào? Tất cả mọi người đăng một câu hỏi trên Stackoverflow dự kiến sẽ cho thấy những gì ông đã cố gắng, những gì ông đã tìm kiếm. – Jocelyn