Skip to content

Progressively render PDF's to images in the browser

Notifications You must be signed in to change notification settings

TheProfs/pdf-to-image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status XO code style

pdf-to-image

Progressively render PDF's as images on the client - cleanly wraps Mozilla/PDF.js

Usage

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>

API

Render all pages

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

// same as above but print only pages 1,2 & 5
pdfToImage.toImages(file, [1, 2, 5]);

Running Tests

$ sudo npm install && npm install -g phantomjs mocha chai
$ npm test

Contributing?

# 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 which is the headless test env. does not support ES6. Read here for more details.

Authors

Owners

License

All portions of the source code are proprietary, excluding third-party libraries.

About

Progressively render PDF's to images in the browser

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages