To save the conversion results to a stream, follow these steps:
Specify the method to obtain the stream where the converted file will be sent.
Pass the method’s name as the document parameter to the convert() method implementations.
The following code snippet shows how to save a file to an OutputStream:
publicstaticvoidRun(){// Create a supplier for the output stream
Supplier<OutputStream>getOutputStream=()->getFileStream("c:\\files\\converted.pdf");Converterconverter=newConverter("c:\\files\\sample.docx");PdfConvertOptionsoptions=newPdfConvertOptions();// Pass the output stream supplier as parameter
converter.convert(getOutputStream.get(),options);System.out.println("\nSource file converted successfully.\nSent file to stream.");}// Obtain the stream for the conversion output
publicstaticOutputStreamgetFileStream(StringoutFile){try{returnnewFileOutputStream(newFile(outFile));}catch(Exceptione){e.printStackTrace();returnnull;}}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.