Uploading a PDF file to Google Docs generated by pdfjet on GAE/J

强颜欢笑 提交于 2019-12-22 17:48:10

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/3996495/uploading-a-pdf-file-to-google-docs-generated-by-pdfjet-on-gae-j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!