https://github.com/theprofs/pdf-to-image
Progressively render PDF's to images in the browser
https://github.com/theprofs/pdf-to-image
image pdf pdfjs
Last synced: 2 months ago
JSON representation
Progressively render PDF's to images in the browser
- Host: GitHub
- URL: https://github.com/theprofs/pdf-to-image
- Owner: TheProfs
- Created: 2017-06-07T11:50:26.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-03-02T10:21:15.000Z (almost 7 years ago)
- Last Synced: 2025-02-17T16:11:23.957Z (10 months ago)
- Topics: image, pdf, pdfjs
- Language: JavaScript
- Homepage:
- Size: 719 KB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.org/TheProfs/pdf-to-image)
[](https://github.com/sindresorhus/xo)
# pdf-to-image
> Progressively render PDF's as images on the client -
cleanly wraps [Mozilla/PDF.js][1]
## Usage
Depends on [Mozilla/PDF.js][1], you can find distribution versions [here][2]
or just grab it from a [CDN][3]
```html
```
## API
### Render all pages
```javascript
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);
```
### Render specific pages
```javascript
// same as above but print only pages 1,2 & 5
pdfToImage.toImages(file, [1, 2, 5]);
```
## Running Tests
```bash
$ sudo npm install && npm install -g phantomjs mocha chai
$ npm test
```
## Contributing?
```bash
# 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
```
### Gotchas
- Always write tests in ES5 as [PhantomJS][4] which is the headless test env.
does not support ES6. Read [here][5] for more details.
## Authors
- Nicholas Kyriakides, [@nicholaswmin][6],
## Owners
- [The Profs LTD][7]
## License
All portions of the source code are proprietary,
excluding third-party libraries.
[1]: https://mozilla.github.io/pdf.js/
[2]: https://github.com/mozilla/pdfjs-dist
[3]: https://cdnjs.cloudflare.com/ajax/libs/pdf.js/1.8.428/pdf.min.js
[4]: http://phantomjs.org/
[5]: https://github.com/nathanboktae/mocha-phantomjs/issues/218
[6]: https://github.com/nicholaswmin
[7]: https://github.com/TheProfs