There might be cases when the document is presented only as a stream (without a copy on the local disk). To avoid the overhead of saving documents to the disk, GroupDocs.Parser enables to extract data from streams directly.
The Parser constructor accepts a Java java.io.InputStream. The package provides the readDataFromStream helper that reads a Node.js readable stream (a file stream, an HTTP response, etc.) and passes its content to the callback as a Java input stream.
The following example shows how to load the document from a Node.js stream:
constfs=require('fs');constgroupdocs=require('@groupdocs/groupdocs.parser');// Read the Node.js stream into a Java input stream
groupdocs.readDataFromStream(fs.createReadStream('sample.pdf'),(stream)=>{// Create an instance of Parser class with the stream
constparser=newgroupdocs.Parser(stream);try{// Extract a text into the reader
constreader=parser.getText();// If text extraction isn't supported, a reader is null
if(reader===null){console.log("Text extraction isn't supported");}else{try{// Print a text from the document
console.log(reader.readToEnd());}finally{reader.close();}}}finally{parser.close();stream.close();}process.exit(0);});
readDataFromStream buffers the whole stream in memory. To read a file with a Java stream instead, create java.io.FileInputStream with the java module:
constjava=require('java');constgroupdocs=require('@groupdocs/groupdocs.parser');constFileInputStream=java.import('java.io.FileInputStream');// Create the stream
conststream=newFileInputStream('sample.pdf');try{// Create an instance of Parser class with the stream
constparser=newgroupdocs.Parser(stream);try{// Extract a text into the reader
constreader=parser.getText();// If text extraction isn't supported, a reader is null
console.log(reader===null?"Text extraction isn't supported":reader.readToEnd());if(reader!==null){reader.close();}}finally{parser.close();}}finally{stream.close();}process.exit(0);
More resources
Free online document parser App
Along with the full-featured library we provide simple but powerful free Apps.
You are welcome to parse documents and extract data from PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our Free Online Document Parser App.
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.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.