I am working on project with pdf's, i want to add a custom watermark to each pages of pdf but only using 'input.pdf' and save it no 'output.pdf'.
I tried with pdf-lib.js but i can't achieve what i want
const fs = require('fs');
const {
writeFileSync,
readFileSync
} = require("fs");
async function createPDF() {
const document = await PDFDocument.load(readFileSync("./f1.pdf-1675923413580.pdf"));
const courierBoldFont = await document.embedFont(StandardFonts.Courier);
const firstPage = document.getPage(0);
const {
width,
height
} = firstPage.getSize()
firstPage.drawText('This text was added with JavaScript!', {
x: 5,
y: height / 2 + 300,
size: 50,
font: courierBoldFont ,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(-45),
})
writeFileSync("./output.pdf", await document.save());
}
createPDF().catch((err) => console.log(err));
Goal input.pdf + watermark = input.pdf done on itself