I am trying to convert html to PDF file using PDFTron
const { PDFNet } = require('@pdftron/pdfnet-node');
async function main() {
// Start with a PDFDoc (the conversion destination)
const doc = await PDFNet.PDFDoc.create();
const converter = await PDFNet.HTML2PDF.create();
// add from HTML String data
converter.insertFromHtmlString(htmlSource);
// add from a web page location
//converter.insertFromUrl(webPageLocation);
// apply conversion
const page = await converter.convert(doc);
//doc.pagePushBack(page);
doc.save('aaa.pdf',PDFNet.SDFDoc.SaveOptions.e_linearized); }
PDFNet.runWithCleanup(main,licenseKey).catch(function(error) {
console.log('Error: ' + JSON.stringify(error));
}).then(function(){ PDFNet.shutdown(); });
, and get the following error:
On the download site: " https://www.pdftron.com/download-center/windows/?language=All#modules-html2pdf-conversion-module%5Cn "
I found no mention of html2PDF.
Does anyone know the problem
You need to download the HTML2PDF module here: https://www.pdftron.com/download-center/windows/?language=All#modules_html2pdf-conversion-module
And then use HTML2PDF.SetModulePath
and pass in the path to the folder where you extracted HTML2PDF
into.
See sample: https://www.pdftron.com/documentation/samples/node/js/HTML2PDFTest/