forked from nextcloud/files_pdfviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdfjs-get.js
31 lines (28 loc) · 990 Bytes
/
pdfjs-get.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const path = require('path')
const unzipper = require('unzipper')
const request = require('request')
const progress = require('request-progress')
const cliProgress = require('cli-progress')
// Fetching pdf.js build release
const PDFJSversion = '2.5.207'
console.info('Fetching pdfjs', PDFJSversion)
// Init progress
const pdfjsProgress = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic)
pdfjsProgress.start(100, 0)
progress(request(`https://github.com/mozilla/pdf.js/releases/download/v${PDFJSversion}/pdfjs-${PDFJSversion}-es5-dist.zip`), {
throttle: 50,
delay: 0,
})
.on('progress', function(state) {
pdfjsProgress.update(state.size.transferred / state.size.total * 100)
})
.on('end', function() {
pdfjsProgress.update(100)
pdfjsProgress.stop()
console.info('Done! \n')
})
.on('error', function(err) {
console.error(err)
throw new Error('Unable to download pdfjs dist')
})
.pipe(unzipper.Extract({ path: path.resolve(__dirname, 'js', 'pdfjs') }))