Hi Jelle,
Please try to install your node module in the folder <project>javascriptsource\<module>\actions
Then you can use the normal import
import { PDFDocument } from "pdf-lib"
Be careful check if the node_module folder is ignored SVN when you commit your project.
Please note the node_modules folder could be huge sometimes… slowing down your svn commits. Therefor you can remove all unused files.
import { PDFDocument } from "pdf-lib"
// BEGIN EXTRA CODE
function saveDocument(imageObject, filename, blob) {
return new Promise((resolve, reject) => {
const guid = imageObject.getGuid();
const onSuccess = () => resolve();
const onError = (error) => reject(error.message);
mx.data.saveDocument(guid, filename, {}, blob, onSuccess, onError);
});
}
// END EXTRA CODE
/**
* @param {MxObject} file
* @returns {Promise.<void>}
*/
export async function CreatePDF(file) {
// BEGIN USER CODE
const pdfDoc = await PDFDocument.create();
const page = pdfDoc.addPage();
page.drawText('You can create PDFs!');
const pdfBytes = await pdfDoc.save();
return saveDocument(file, "my file.pdf", new Blob([pdfBytes]));
// END USER CODE
}
Cheers, Andries