There might be a case when your file is not physically located on the disk. Instead, you have the file in the form of a stream. In this case, to avoid the overhead of saving the stream as a file on disk, GroupDocs.Conversion enables you to convert the file streams directly.
To load a file from a stream, follow these steps:
Specify the method to obtain the file stream.
Pass the method’s name to the Converter class constructor.
The following code snippet serves this purpose:
constfs=require('fs')constoutputPath="LoadDocumentFromStream.pdf"try{constreadStream=fs.createReadStream("sample.docx")conststream=awaitgroupdocs.conversion.readDataFromStream(readStream)constconverter=newgroupdocs.conversion.Converter(stream);constconvertOptions=newgroupdocs.conversion.PdfConvertOptions()console.log(`Source document converted successfully to ${outputPath}`)returnconverter.convert(outputPath,convertOptions)}catch(error){thrownewError(error)}
The snippet above uses the createReadStream method. Similarly, you can use any other type of stream. Just make sure that the source stream contains any of the supported file formats.
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.