Download the Net Zero Guidelines

www.our2050.world/dcc/?dname=Daniel Barlow&dorg=Our 2050 World

Probably need to find a way to capture results of download – could plausible do it?

Modify Document (pdf-lib) – JSFiddle – Code Playground https://jsfiddle.net/3us6Lew5/

Next.js API: Watermark PDF using query parameters in URL – Stack Overflow

https://stackoverflow.com/questions/69318155/next-js-api-watermark-pdf-using-query-parameters-in-url

This code worked as a snipit:

<input id=”user” value=””>
<script>
var url = window.location.href; //window.location.href
var name = url.substring(url.indexOf(“=”) + 1);
document.getElementById(“user”).value = name;
</script>
<html>
<head>
<meta charset=”utf-8″ />
<script src=”https://unpkg.com/pdf-lib@1.4.0″></script>
<script src=”https://unpkg.com/downloadjs@1.4.7″></script>
</head>

<body>

<button onclick=”modifyPdf()”>Download</button>
<p class=”small”>(Your browser will download the resulting file)</p>
</body>

<script>
// old from here
const { degrees, PDFDocument, rgb, StandardFonts } = PDFLib
var url = window.location.href; //window.location.href
var name = url.substring(url.indexOf(“=”) + 1);
async function modifyPdf() {
// Fetch an existing PDF document
const url = ‘https://our2050.world/wp-content/uploads/2022/10/Net-Zero-Guidelines-empty.pdf’
const existingPdfBytes = await fetch(url).then(res => res.arrayBuffer())

// Load a PDFDocument from the existing PDF bytes
const pdfDoc = await PDFDocument.load(existingPdfBytes)

// Embed the Helvetica font
const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica)

// Get the first page of the document
const pages = pdfDoc.getPages()
const firstPage = pages[0]

// Get the width and height of the first page
const { width, height } = firstPage.getSize()

// Draw a string
firstPage.drawText(‘Downloaded by ‘ + name, {
x: 5,
y: height – 100,
size: 10,
font: helveticaFont,
color: rgb(0.5, 0.5, 0.5),
rotate: degrees(-90),
})

// Serialize the PDFDocument to bytes (a Uint8Array)
const pdfBytes = await pdfDoc.save()

// Trigger the browser to download the PDF document
download(pdfBytes, “Net Net-Zero-Guidelines-empty.pdf”, “application/pdf”);
}
</script>
</html>