Source code

Revision control

Other Tools

<!doctype html>
<title></title>
<script src="/_pdf_js/pdf.js"></script>
<canvas></canvas>
<script>
function render(pdfData) {
return _render(pdfData);
}
async function _render(pdfData) {
let loadingTask = pdfjsLib.getDocument({data: atob(pdfData)});
let pdf = await loadingTask.promise;
let rendered = [];
for (let pageNumber=1; pageNumber<=pdf.numPages; pageNumber++) {
let page = await pdf.getPage(pageNumber);
var viewport = page.getViewport({scale: 96./72.});
// Prepare canvas using PDF page dimensions
var canvas = document.getElementsByTagName('canvas')[0];
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
// Render PDF page into canvas context
var renderContext = {
canvasContext: context,
viewport: viewport
};
await page.render(renderContext).promise;
rendered.push(canvas.toDataURL());
}
return rendered;
}
</script>