将 GAE/J 上的 pdfjet 生成的 PDF 文件上传到 Google Docs

发布于 2024-09-28 11:28:20 字数 597 浏览 0 评论 0原文

我需要将 PDF 文件上传到用户谷歌文档,该文件是由谷歌应用引擎上的 pdfjet 生成的。我想出使用 pdfjet for gae/j 生成 pdf。 pdfjet 使用流来创建 pdf。无论如何,是否可以将流转换为文件,以便我可以上传给用户谷歌文档。我尝试了 gaevfs 但无法使其工作。如果需要,我可以使用另一个 pdf 生成解决方案或另一个虚拟文件系统等。

PDF 生成代码

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

Google Docs API 代码

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

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

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

谢谢。

I need to upload a PDF file to users google docs which is generated by pdfjet on google app engine. I figure out to generate pdf using pdfjet for gae/j. pdfjet uses streams to create the pdf. Is there anyway to convert stream to file so I can upload to users google docs. I tried gaevfs but couldn't make it work. I can use another pdf generation solution if needed or another virtual file system etc.

PDF generation code

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

Google Docs API code

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

The line I couldn't get make it work : setFile(File, String)

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

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软甜啾 2024-10-05 11:28:20

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

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

Couldn't you simply write from ByteArrayOutputStream to FileOutputStream using the ByteArrayOutputStream.writeTo(OutputStream) method? Like this:

ByteArrayOutputStream os = new ByteArrayOutputStream();
PDF pdf = new PDF(os);  
FileOutputStream fos = new FileOutputStream("myPDF.pdf");
baos.writeTo(os);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文