Public
Edited
Nov 13, 2023
Paused
19 stars
Insert cell
Insert cell
pdfjs = {
const version = "4.0";
const lib = await import(`https://cdn.jsdelivr.net/npm/pdfjs-dist@${version}/+esm`);
lib.GlobalWorkerOptions.workerSrc = `https://cdn.jsdelivr.net/npm/pdfjs-dist@${version}/build/pdf.worker.mjs`;
return lib;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// FileAttachment
attachedFileDoc = pdfjs.getDocument({
data: await FileAttachment("helloworld.pdf").arrayBuffer()
}).promise
Insert cell
// Remote URL (which we'll be using throughout the rest of this notebook)
remoteUrlDoc = pdfjs.getDocument({
url: await FileAttachment("helloworld.pdf").url()
}).promise
Insert cell
page = remoteUrlDoc.getPage(pageNum)
Insert cell
Insert cell
{
const canvas = html`<canvas width=${width} height=500 style="border: 1px solid #aaa">`;
page.render({
canvasContext: canvas.getContext("2d"),
viewport: page.getViewport({scale: 1.5}),
});
return canvas;
}
Insert cell
Insert cell
content = await page.getTextContent({
includeMarkedContent: false,
})
Insert cell
Inputs.table(content.items)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more