Update remaining examples, and docs, to utilize current API functionality (issue 10377)

This contains a couple of changes that I missed elsewhere, sorry about that!
This commit is contained in:
Jonas Jenwald 2018-12-24 12:28:20 +01:00
parent 103f4616ac
commit 9962ab66ab
4 changed files with 13 additions and 12 deletions

View File

@ -20,10 +20,11 @@ The object structure of PDF.js loosely follows the structure of an actual PDF. A
pdfjsLib.getDocument('helloworld.pdf')
```
Remember though that PDF.js uses promises, so the above will return a promise that is resolved with the document object.
Remember though that PDF.js uses promises, and the above will return a `PDFDocumentLoadingTask` instance that has a `promise` property which is resolved with the document object.
```js
pdfjsLib.getDocument('helloworld.pdf').then(function(pdf) {
var loadingTask = pdfjsLib.getDocument('helloworld.pdf');
loadingTask.promise.then(function(pdf) {
// you can now use *pdf* here
});
```
@ -42,7 +43,7 @@ Each PDF page has its own viewport which defines the size in pixels(72DPI) and i
```js
var scale = 1.5;
var viewport = page.getViewport(scale);
var viewport = page.getViewport({ scale: scale, });
var canvas = document.getElementById('the-canvas');
var context = canvas.getContext('2d');
@ -60,9 +61,9 @@ Alternatively, if you want the canvas to render to a certain pixel size you coul
```js
var desiredWidth = 100;
var viewport = page.getViewport(1);
var viewport = page.getViewport({ scale: 1, });
var scale = desiredWidth / viewport.width;
var scaledViewport = page.getViewport(scale);
var scaledViewport = page.getViewport({ scale: scale, });
```
## Interactive examples

View File

@ -35,7 +35,7 @@
//
pdf.getPage(1).then(function(page) {
var scale = 1.5;
var viewport = page.getViewport(scale);
var viewport = page.getViewport({ scale: scale, });
//
// Prepare canvas using PDF page dimensions
@ -50,7 +50,7 @@
//
var renderContext = {
canvasContext: context,
viewport: viewport
viewport: viewport,
};
page.render(renderContext);
});

View File

@ -39,12 +39,12 @@
// Opening PDF by passing its binary data as a string. It is still preferable
// to use Uint8Array, but string or array-like structure will work too.
var loadingTask = pdfjsLib.getDocument({data: pdfData});
var loadingTask = pdfjsLib.getDocument({ data: pdfData, });
loadingTask.promise.then(function(pdf) {
// Fetch the first page.
pdf.getPage(1).then(function(page) {
var scale = 1.5;
var viewport = page.getViewport(scale);
var viewport = page.getViewport({ scale: scale, });
// Prepare canvas using PDF page dimensions.
var canvas = document.getElementById('the-canvas');
@ -55,7 +55,7 @@
// Render PDF page into canvas context.
var renderContext = {
canvasContext: context,
viewport: viewport
viewport: viewport,
};
page.render(renderContext);
});

View File

@ -52,14 +52,14 @@
pageRendering = true;
// Using promise to fetch the page
pdfDoc.getPage(num).then(function(page) {
var viewport = page.getViewport(scale);
var viewport = page.getViewport({ scale: scale, });
canvas.height = viewport.height;
canvas.width = viewport.width;
// Render PDF page into canvas context
var renderContext = {
canvasContext: ctx,
viewport: viewport
viewport: viewport,
};
var renderTask = page.render(renderContext);