将文档上传到Google云端硬盘并设置其纸张大小 [英] Uploading a document to Google Drive and setting its paper size

查看:658
本文介绍了将文档上传到Google云端硬盘并设置其纸张大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Java库上传HTML文件并将其转换为本机Google文档。这里是代码:

I use the Java library to upload an HTML file and convert it to native Google document. Here is the code:

String title = "Doc title";
byte[] data = <doc data>;
...

File fileMetadata = new File();
fileMetadata.setTitle(title);
fileMetadata.setMimeType("text/html");
InputStreamContent mediaContent = new InputStreamContent("text/html", new ByteArrayInputStream(data));
mediaContent.setLength(data.length);

Drive.Files.Insert insert = service.files().insert(fileMetadata, mediaContent);
insert.setConvert(true);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(true);

insert.execute();

只有一个例外 - 它创建一个纸张大小设置为Letter的文档。对于我的帐户,默认值为A4,我希望新创建的文档采用这种格式。

Works great with one exception - it creates a document with paper size set to Letter. For my account the default is A4 and I want the newly created document to be in this format.

有谁知道设置上传文档纸张大小的方法吗?

Does anyone know a way set the paper size of the uploaded document?

预先感谢。

推荐答案

转换为Google文档,并且没有独立的API来操纵Google文档。您可以通过 Google Apps脚本,但它可能不容易与您的代码集成。

Unfortunately there are no options to configure the conversion to Google Docs, and there is no standalone API to manipulate Google Docs. You can change the page width and height via Google Apps Script, but it would likely not be simple to integrate with your code.

这篇关于将文档上传到Google云端硬盘并设置其纸张大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆