Skip to content

Commit

Permalink
Merge pull request #10378 from Snuffleupagus/issue-10377
Browse files Browse the repository at this point in the history
Update remaining examples, and docs, to utilize current API functionality (issue 10377)
  • Loading branch information
timvandermeij committed Dec 24, 2018
2 parents 103f461 + 9962ab6 commit 2e05827
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
11 changes: 6 additions & 5 deletions docs/contents/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
```
Expand All @@ -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');
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/learning/helloworld.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h1>'Hello, world!' example</h1>
//
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
Expand All @@ -50,7 +50,7 @@ <h1>'Hello, world!' example</h1>
//
var renderContext = {
canvasContext: context,
viewport: viewport
viewport: viewport,
};
page.render(renderContext);
});
Expand Down
6 changes: 3 additions & 3 deletions examples/learning/helloworld64.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ <h1>'Hello, world!' example</h1>

// 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');
Expand All @@ -55,7 +55,7 @@ <h1>'Hello, world!' example</h1>
// Render PDF page into canvas context.
var renderContext = {
canvasContext: context,
viewport: viewport
viewport: viewport,
};
page.render(renderContext);
});
Expand Down
4 changes: 2 additions & 2 deletions examples/learning/prevnext.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ <h1>'Previous/Next' example</h1>
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);

Expand Down

0 comments on commit 2e05827

Please sign in to comment.