converted examples/text-only/pdf2svg.js to await/async
Updated promise call back with await/async method
This commit is contained in:
parent
f6d9d91965
commit
fdf08ef3d2
@ -48,19 +48,16 @@ function buildSVG(viewport, textContent) {
|
|||||||
return svg;
|
return svg;
|
||||||
}
|
}
|
||||||
|
|
||||||
function pageLoaded() {
|
async function pageLoaded() {
|
||||||
// Loading document and page text content
|
// Loading document and page text content
|
||||||
const loadingTask = pdfjsLib.getDocument({ url: PDF_PATH });
|
const loadingTask = pdfjsLib.getDocument({ url: PDF_PATH });
|
||||||
loadingTask.promise.then(function (pdfDocument) {
|
const pdfDocument = await loadingTask.promise;
|
||||||
pdfDocument.getPage(PAGE_NUMBER).then(function (page) {
|
const page = await pdfDocument.getPage(PAGE_NUMBER);
|
||||||
const viewport = page.getViewport({ scale: PAGE_SCALE });
|
const viewport = page.getViewport({ scale: PAGE_SCALE });
|
||||||
page.getTextContent().then(function (textContent) {
|
const textContent = await page.getTextContent();
|
||||||
// building SVG and adding that to the DOM
|
// building SVG and adding that to the DOM
|
||||||
const svg = buildSVG(viewport, textContent);
|
const svg = buildSVG(viewport, textContent);
|
||||||
document.getElementById("pageContainer").appendChild(svg);
|
document.getElementById("pageContainer").appendChild(svg);
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user