Page 1 of 1

Output PDF to memory, not file

PostPosted: Tue Dec 08, 2015 9:24 am
by WorldsEndless
I am building a web app in which faculty submit docx documents, which are stored in MongoDB. I need convert these documents (there will be 12-16 of them) into PDF and then merge them in to a single PDF. I can do this if I write each docx to disk, then convert it to pdf, then merge those; but I would like to avoid writing to disk at all. I believe that WordprocessingMLPackage/load can read my docx input stream (rather than a hard file), which is good; but how can I write to an output stream that isn't an on-disk file?

Re: Output PDF to memory, not file

PostPosted: Tue Dec 08, 2015 11:59 am
by jason
Use whatever outputstream you want:

https://github.com/plutext/docx4j/blob/ ... .java#L472

public static void toPDF(WordprocessingMLPackage wmlPackage, OutputStream outputStream) throws Docx4JException

for example https://github.com/plutext/docx4j/blob/ ... .java#L176

Or you can use Plutext's commercial PDF Converter without writing to disk either.