Merge pull request #14299 from SaiKiranMukka/pageviewer-to-async

Convert examples/components/pageviewer.js to await/async (issue 14127)
This commit is contained in:
Jonas Jenwald 2021-11-24 14:52:31 +01:00 committed by GitHub
commit 5e2aec7dd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,9 +47,10 @@ const loadingTask = pdfjsLib.getDocument({
cMapPacked: CMAP_PACKED, cMapPacked: CMAP_PACKED,
enableXfa: ENABLE_XFA, enableXfa: ENABLE_XFA,
}); });
loadingTask.promise.then(function (pdfDocument) { (async function () {
const pdfDocument = await loadingTask.promise;
// Document loaded, retrieving the page. // Document loaded, retrieving the page.
return pdfDocument.getPage(PAGE_TO_VIEW).then(function (pdfPage) { const pdfPage = await pdfDocument.getPage(PAGE_TO_VIEW);
// Creating the page view with default parameters. // Creating the page view with default parameters.
const pdfPageView = new pdfjsViewer.PDFPageView({ const pdfPageView = new pdfjsViewer.PDFPageView({
container, container,
@ -70,5 +71,4 @@ loadingTask.promise.then(function (pdfDocument) {
// Associate the actual page with the view, and draw it. // Associate the actual page with the view, and draw it.
pdfPageView.setPdfPage(pdfPage); pdfPageView.setPdfPage(pdfPage);
return pdfPageView.draw(); return pdfPageView.draw();
}); })();
});