Merge pull request #9618 from timvandermeij/node-example
Improve the instructions and code for the `pdf2png` example
This commit is contained in:
commit
57e8676180
@ -4,12 +4,13 @@ Example to demonstrate converting a PDF file to a PNG image using the PDF.js lib
|
|||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
|
|
||||||
Install the dependencies and build the project:
|
Install the dependencies and build the PDF.js library:
|
||||||
|
|
||||||
$ npm install
|
$ npm install
|
||||||
$ gulp dist
|
$ gulp dist-install
|
||||||
|
|
||||||
Install the Node canvas library to convert the first page of a PDF file to a PNG image:
|
Install the Node canvas library and run the example to convert the first page of a
|
||||||
|
PDF file to a PNG image:
|
||||||
|
|
||||||
$ npm install canvas
|
$ npm install canvas
|
||||||
$ cd examples/node/pdf2png
|
$ cd examples/node/pdf2png
|
||||||
|
@ -51,13 +51,19 @@ NodeCanvasFactory.prototype = {
|
|||||||
var pdfjsLib = require('pdfjs-dist');
|
var pdfjsLib = require('pdfjs-dist');
|
||||||
|
|
||||||
// Relative path of the PDF file.
|
// Relative path of the PDF file.
|
||||||
var pdfURL = '../../helloworld/helloworld.pdf';
|
var pdfURL = '../../../web/compressed.tracemonkey-pldi-09.pdf';
|
||||||
|
|
||||||
// Read the PDF file into a typed array so PDF.js can load it.
|
// Read the PDF file into a typed array so PDF.js can load it.
|
||||||
var rawData = new Uint8Array(fs.readFileSync(pdfURL));
|
var rawData = new Uint8Array(fs.readFileSync(pdfURL));
|
||||||
|
|
||||||
// Load the PDF file.
|
// Load the PDF file. The `disableFontFace` and `nativeImageDecoderSupport`
|
||||||
pdfjsLib.getDocument(rawData).then(function (pdfDocument) {
|
// options must be passed because Node.js has no native `@font-face` and
|
||||||
|
// `Image` support.
|
||||||
|
pdfjsLib.getDocument({
|
||||||
|
data: rawData,
|
||||||
|
disableFontFace: true,
|
||||||
|
nativeImageDecoderSupport: 'none',
|
||||||
|
}).then(function (pdfDocument) {
|
||||||
console.log('# PDF document loaded.');
|
console.log('# PDF document loaded.');
|
||||||
|
|
||||||
// Get the first page.
|
// Get the first page.
|
||||||
|
Loading…
Reference in New Issue
Block a user