mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Improve the instructions and code for the pdf2png
example
We need to pass `disableFontFace` and `nativeImageDecoderSupport` because Node.js has no native support for `@font-face` and `Image`. Doing so makes it possible to render e.g., the Tracemonkey paper, which failed before. I made this PDF file the default because it's also the default in other examples/demos and because it showcases the possibilities better than the very simple hello world PDF file. Building the library with `gulp dist-install` is easier and is already recommended in the other examples.
This commit is contained in:
parent
8887a09e8f
commit
64b1315bb5
2 changed files with 13 additions and 6 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue