Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the instructions and code for the pdf2png example #9618

Merged
merged 1 commit into from
Apr 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/node/pdf2png/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ Example to demonstrate converting a PDF file to a PNG image using the PDF.js lib

## Getting started

Install the dependencies and build the project:
Install the dependencies and build the PDF.js library:

$ 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
$ cd examples/node/pdf2png
Expand Down
12 changes: 9 additions & 3 deletions examples/node/pdf2png/pdf2png.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ NodeCanvasFactory.prototype = {
var pdfjsLib = require('pdfjs-dist');

// 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.
var rawData = new Uint8Array(fs.readFileSync(pdfURL));

// Load the PDF file.
pdfjsLib.getDocument(rawData).then(function (pdfDocument) {
// Load the PDF file. The `disableFontFace` and `nativeImageDecoderSupport`
// 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.');

// Get the first page.
Expand Down