Merge pull request #14141 from adenicole/master

Convert examples/text-only/pdf2svg.js to await/async
This commit is contained in:
Jonas Jenwald 2021-10-15 11:35:05 +02:00 committed by GitHub
commit fc56a781d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,19 +48,16 @@ function buildSVG(viewport, textContent) {
return svg;
}
function pageLoaded() {
async function pageLoaded() {
// Loading document and page text content
const loadingTask = pdfjsLib.getDocument({ url: PDF_PATH });
loadingTask.promise.then(function (pdfDocument) {
pdfDocument.getPage(PAGE_NUMBER).then(function (page) {
const viewport = page.getViewport({ scale: PAGE_SCALE });
page.getTextContent().then(function (textContent) {
// building SVG and adding that to the DOM
const svg = buildSVG(viewport, textContent);
document.getElementById("pageContainer").appendChild(svg);
});
});
});
const pdfDocument = await loadingTask.promise;
const page = await pdfDocument.getPage(PAGE_NUMBER);
const viewport = page.getViewport({ scale: PAGE_SCALE });
const textContent = await page.getTextContent();
// building SVG and adding that to the DOM
const svg = buildSVG(viewport, textContent);
document.getElementById("pageContainer").appendChild(svg);
}
document.addEventListener("DOMContentLoaded", function () {