pdf.js/examples/browserify/main.js
Jonas Jenwald f0719ed565 [api-minor] Change the getViewport method, on PDFPageProxy, to take a parameter object rather than a bunch of (randomly) ordered parameters
If, as PR 10368 suggests, more parameters should be added to `getViewport` I think that it would be a mistake to not change the signature *first* to avoid needlessly unwieldy call-sites.

To not break any existing code and third-party use-cases, this is obviously implemented with a deprecation warning *and* with a working fallback[1] for the old method signature.

---
[1] This is limited to `GENERIC` builds, which should be sufficient.
2018-12-21 11:55:20 +01:00

34 lines
1.0 KiB
JavaScript

// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/licenses/publicdomain/
// Hello world example for browserify.
var pdfjsLib = require('pdfjs-dist');
var pdfPath = '../helloworld/helloworld.pdf';
// Setting worker path to worker bundle.
pdfjsLib.GlobalWorkerOptions.workerSrc =
'../../build/browserify/pdf.worker.bundle.js';
// Loading a document.
var loadingTask = pdfjsLib.getDocument(pdfPath);
loadingTask.promise.then(function (pdfDocument) {
// Request a first page
return pdfDocument.getPage(1).then(function (pdfPage) {
// Display page on the existing canvas with 100% scale.
var viewport = pdfPage.getViewport({ scale: 1.0, });
var canvas = document.getElementById('theCanvas');
canvas.width = viewport.width;
canvas.height = viewport.height;
var ctx = canvas.getContext('2d');
var renderTask = pdfPage.render({
canvasContext: ctx,
viewport: viewport,
});
return renderTask.promise;
});
}).catch(function (reason) {
console.error('Error: ' + reason);
});