Using word-extractor on browser

Install word-extractor and blob-to-buffer:

1
npm install --save word-extractor blob-to-buffer

Install browserify dependendcies:

1
npm install --save assert buffer events path-browserify process stream-browserify util browserify-zlib

Add webpack fallback configuration:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module.exports = {
// omitted
resolve: {
fallback: {
assert: require.resolve('assert'),
buffer: require.resolve('buffer'),
events: require.resolve('events'),
path: require.resolve('path-browserify'),
process: require.resolve('process/browser'),
stream: require.resolve('stream-browserify'),
util: require.resolve('util'),
zlib: require.resolve('browserify-zlib'),
},
},
};

Read a file with File API and extract from it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const blobToBuffer = require('blob-to-buffer');

// acquire file (`File` object) somehow
blobToBuffer(file, (error, buffer) => {
if (error) {
// error handling
} else {
const wordExtractor = new WordExtractor();
wordExtractor.extract(buffer).then((doc) => {
// play with the document
}).catch(() => {
// error handling
});
}
});