将PDF文件上传到由pdfjet在GAE / J上生成的Google文档

时间:2010-10-22 11:51:16

标签: java google-app-engine pdf-generation google-docs-api

我需要将PDF文件上传到用户google文档,这是由谷歌应用引擎上的pdfjet生成的。我想用pdfjet为gae / j生成pdf。 pdfjet使用流来创建pdf。反正有没有将流转换为文件,所以我可以上传到用户谷歌文档。我试过gaevfs,但无法使它工作。如果需要,我可以使用另一种pdf生成解决方案或其他虚拟文件系统等。

PDF生成代码

ByteArrayOutputStream os = new ByteArrayOutputStream();
PDF pdf = new PDF(os);

Google文档API代码

DocumentListEntry newEntry = new PdfEntry();
newEntry.setTitle(new PlainTextConstruct("Some Report"));

我无法使用的行使其工作:setFile(File,String)

newEntry.setFile(pdf, "application/pdf");

感谢。

1 个答案:

答案 0 :(得分:0)

你不能简单地使用ByteArrayOutputStream方法从FileOutputStream写到ByteArrayOutputStream.writeTo(OutputStream)吗?像这样:

ByteArrayOutputStream os = new ByteArrayOutputStream();
PDF pdf = new PDF(os);  
FileOutputStream fos = new FileOutputStream("myPDF.pdf");
baos.writeTo(os);