cancel
Showing results for 
Search instead for 
Did you mean: 

Generating PDF from custom HTML template using node.js in SAP BTP CAPM

Ram121
Newcomer
0 Kudos
136

I am generating PDF from custom HTML template using one of node.js library puppeteer. But I am getting an issue in BAS. Error: Failed to launch the browser process!
/home/user/.cache/puppeteer/chrome/linux-131.0.6778.85/chrome-linux64/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory.

But it is working properly in VS code. 

My Code:-

const puppeteer = require('puppeteer');
const { fetchPDFTemplate } = require('./fetch');

async function generatePDF() {
    const htmlTemplate = await fetchPDFTemplate();
    console.log(htmlTemplate);

    // Define the replacements
    const replacements = {
        'P.S.Number': '123456',
        'Date': '12/04/2024',
        'Salutation': 'Mr.',
        'Name': 'John Doe',
        'Overseas-assignment-begindate': '01/01/2020',
        'EmployeeDesignation': 'Software Engineer',
        'PSA': 'USA',
        'visatype': 'H1B',
        'CTC': '100000',
        'currency': 'USD',
        'AddressLine1': '123 Main St',
        'AddressLine2': 'Apt 4B',
        'AddressLine3': '',
        'State': 'California',
        'City': 'Los Angeles',
        'PinCode': '90001',
        'Country': 'USA',
        'FooterLine1': 'Footer Line 1',
        'FooterLine2': 'Footer Line 2'
    };

    // Replace placeholders in the HTML template
    let filledTemplate = htmlTemplate;
    for (const [key, value] of Object.entries(replacements)) {
        const regex = new RegExp(`\\[\\[${key}\\]\\]`, 'g');
        filledTemplate = filledTemplate.replace(regex, value);
    }

    // Generate PDF using Puppeteer
    const browser = await puppeteer.launch({ headless: true });
    const page = await browser.newPage();
    await page.setContent(filledTemplate);
    await page.pdf({
        path: 'output.pdf',
        format: 'A4',
        preferCSSPageSize: true
    });

    await browser.close();
    console.log('PDF generated successfully!');
}

generatePDF();
 
Could you please help me on this if anyone know. How to install those missing dependencies in BAS.
 
 

Accepted Solutions (0)

Answers (0)