Public
Edited
Mar 23, 2024
40 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
htl.html`<a href=${url} download="output.pdf">download</a>` // Link to download PDF
Insert cell
mutable pdfchange = undefined // holds file chooser events (so we can read uploaded files)
Insert cell
Insert cell
mutable sigchange = [] // holds file chooser events (so we can read uploaded files)
Insert cell
pdf = pdfchange.target.files[0] // PDF file
Insert cell
fixedDoc = await pdfLib.PDFDocument.load(await pdf.arrayBuffer()) // PDF we do not manipulate (so we can read parameters without
Insert cell
pdfDoc = (config, await pdfLib.PDFDocument.load(await pdf.arrayBuffer())) // PDF we will mutate
Insert cell
embed = promiseRecursive(
// Mutate PDF, overlays images onto pdf
sigchange.map(async (sig, i) => {
if (!sig.target.files[0]) return "N/A";

const page = pdfDoc.getPage(config.sigs[i].page - 1);
const jpgImage = await pdfDoc.embedJpg(
await sig.target.files[0].arrayBuffer()
);
page.drawImage(jpgImage, {
x: config.sigs[i].sX,
y: config.sigs[i].sY,
width: config.sigs[i].sW,
height: config.sigs[i].sH
});

return "OK";
})
)
Insert cell
url = {
// Generate a blob representing the rendered PDF
embed; // make sure image is in it first
const file = new Blob([await pdfDoc.save()], {
type: "application/pdf"
});
return URL.createObjectURL(file);
}
Insert cell
sigUrls = promiseRecursive(
// Generate a blobs for the signatures
sigchange.map(async (sig, i) => {
if (!sig.target.files[0]) return undefined;
const file = new Blob([await sig.target.files[0].arrayBuffer()], {
type: "image/jpg"
});
return URL.createObjectURL(file);
})
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more