Skip to content

Commit 5e2aec7

Browse files
Merge pull request #14299 from SaiKiranMukka/pageviewer-to-async
Convert examples/components/pageviewer.js to await/async (issue 14127)
2 parents 70fc30d + 711fbe1 commit 5e2aec7

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

examples/components/pageviewer.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,28 @@ const loadingTask = pdfjsLib.getDocument({
4747
cMapPacked: CMAP_PACKED,
4848
enableXfa: ENABLE_XFA,
4949
});
50-
loadingTask.promise.then(function (pdfDocument) {
50+
(async function () {
51+
const pdfDocument = await loadingTask.promise;
5152
// Document loaded, retrieving the page.
52-
return pdfDocument.getPage(PAGE_TO_VIEW).then(function (pdfPage) {
53-
// Creating the page view with default parameters.
54-
const pdfPageView = new pdfjsViewer.PDFPageView({
55-
container,
56-
id: PAGE_TO_VIEW,
57-
scale: SCALE,
58-
defaultViewport: pdfPage.getViewport({ scale: SCALE }),
59-
eventBus,
60-
// We can enable text/annotation/xfa/struct-layers, as needed.
61-
textLayerFactory: !pdfDocument.isPureXfa
62-
? new pdfjsViewer.DefaultTextLayerFactory()
63-
: null,
64-
annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(),
65-
xfaLayerFactory: pdfDocument.isPureXfa
66-
? new pdfjsViewer.DefaultXfaLayerFactory()
67-
: null,
68-
structTreeLayerFactory: new pdfjsViewer.DefaultStructTreeLayerFactory(),
69-
});
70-
// Associate the actual page with the view, and draw it.
71-
pdfPageView.setPdfPage(pdfPage);
72-
return pdfPageView.draw();
53+
const pdfPage = await pdfDocument.getPage(PAGE_TO_VIEW);
54+
// Creating the page view with default parameters.
55+
const pdfPageView = new pdfjsViewer.PDFPageView({
56+
container,
57+
id: PAGE_TO_VIEW,
58+
scale: SCALE,
59+
defaultViewport: pdfPage.getViewport({ scale: SCALE }),
60+
eventBus,
61+
// We can enable text/annotation/xfa/struct-layers, as needed.
62+
textLayerFactory: !pdfDocument.isPureXfa
63+
? new pdfjsViewer.DefaultTextLayerFactory()
64+
: null,
65+
annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(),
66+
xfaLayerFactory: pdfDocument.isPureXfa
67+
? new pdfjsViewer.DefaultXfaLayerFactory()
68+
: null,
69+
structTreeLayerFactory: new pdfjsViewer.DefaultStructTreeLayerFactory(),
7370
});
74-
});
71+
// Associate the actual page with the view, and draw it.
72+
pdfPageView.setPdfPage(pdfPage);
73+
return pdfPageView.draw();
74+
})();

0 commit comments

Comments
 (0)