1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Convert examples/components/pageviewer.js to await/async (issue 14127)

This commit is contained in:
Sai Kiran Mukka 2021-11-24 13:25:36 +05:30
parent 70fc30d97c
commit 711fbe1376

View file

@ -47,28 +47,28 @@ 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,
id: PAGE_TO_VIEW, id: PAGE_TO_VIEW,
scale: SCALE, scale: SCALE,
defaultViewport: pdfPage.getViewport({ scale: SCALE }), defaultViewport: pdfPage.getViewport({ scale: SCALE }),
eventBus, eventBus,
// We can enable text/annotation/xfa/struct-layers, as needed. // We can enable text/annotation/xfa/struct-layers, as needed.
textLayerFactory: !pdfDocument.isPureXfa textLayerFactory: !pdfDocument.isPureXfa
? new pdfjsViewer.DefaultTextLayerFactory() ? new pdfjsViewer.DefaultTextLayerFactory()
: null, : null,
annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(), annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(),
xfaLayerFactory: pdfDocument.isPureXfa xfaLayerFactory: pdfDocument.isPureXfa
? new pdfjsViewer.DefaultXfaLayerFactory() ? new pdfjsViewer.DefaultXfaLayerFactory()
: null, : null,
structTreeLayerFactory: new pdfjsViewer.DefaultStructTreeLayerFactory(), structTreeLayerFactory: new pdfjsViewer.DefaultStructTreeLayerFactory(),
});
// Associate the actual page with the view, and draw it.
pdfPageView.setPdfPage(pdfPage);
return pdfPageView.draw();
}); });
}); // Associate the actual page with the view, and draw it.
pdfPageView.setPdfPage(pdfPage);
return pdfPageView.draw();
})();