From fdf08ef3d26d7d1446ddb019668b6a71373163fc Mon Sep 17 00:00:00 2001 From: adenicole Date: Thu, 14 Oct 2021 14:44:00 +0100 Subject: [PATCH] converted examples/text-only/pdf2svg.js to await/async Updated promise call back with await/async method --- examples/text-only/pdf2svg.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/examples/text-only/pdf2svg.js b/examples/text-only/pdf2svg.js index e00e7fbea..201460324 100644 --- a/examples/text-only/pdf2svg.js +++ b/examples/text-only/pdf2svg.js @@ -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 () {