Progressively render PDF's as images on the client - cleanly wraps Mozilla/PDF.js
Depends on Mozilla/PDF.js, you can find distribution versions here or just grab it from a CDN
<!-- Include PDF.js and pdf-to-image.js in this order -->
<script src="dist/pdf-to-image-dist.js"></script>
<script src="pdfjs/pdf.min.js"></script>
const pdfToImage = new PdfToImage();
pdfToImage.addListener('page', result => {
/*
* result includes:
* - pageNum: Number: The page number
* - blob: Blob: A JPEG image blob of each page
*/
});
pdfToImage.addListener('finish', () => {
// called when all pages have finished rendering
});
pdfToImage.addListener('error', err => {
// called if an error occurred during rendering
});
// Where file is PDF File created by a FileReader instance
pdfToImage.toImages(file);
// same as above but print only pages 1,2 & 5
pdfToImage.toImages(file, [1, 2, 5]);
$ sudo npm install && npm install -g phantomjs mocha chai
$ npm test
# Install deps
$ sudo npm install -g mocha chai babel-cli concat-cli xo
# Run linter
$ npm run lint
# - Transpile src/pdf-to-image.js from ES2016 -> ES5 and..
# - Bundle it together with all .js files in src/lib/ and put it in dist/
$ npm run build
- Always write tests in ES5 as PhantomJS which is the headless test env. does not support ES6. Read here for more details.
- Nicholas Kyriakides, @nicholaswmin, nik.kyriakides@gmail.com
All portions of the source code are proprietary, excluding third-party libraries.