I need to modify a PDF on a Apps script application. To do that I want to use a JS library : PDF-LIB
my code :
eval(UrlFetchApp.fetch("https://unpkg.com/pdf-lib/dist/pdf-lib.js").getContentText());
function modifyPdf() {
const url = 'https://pdf-lib.js.org/assets/with_update_sections.pdf'
const existingPdfBytes = UrlFetchApp.fetch(url).getContentText();
const pdfDoc = PDFDocument.load(existingPdfBytes)
const helveticaFont = pdfDoc.embedFont(StandardFonts.Helvetica)
const pages = pdfDoc.getPages()
const firstPage = pages[0]
const { width, height } = firstPage.getSize()
firstPage.drawText('This text was added with JavaScript!', {
x: 5,
y: height / 2 + 300,
size: 50,
font: helveticaFont,
color: rgb(0.95, 0.1, 0.1),
rotate: degrees(-45),
})
const pdfBytes = pdfDoc.save()
}
When I execute the function modifyPDF
I have :
Error
ReferenceError: PDFDocument is not defined modifyPdf @ modifie_pdf.gs:7
Do you know how I can import the js lib on my Apps script application ?