Open binupillai305 opened 2 years ago
What version of NodeJS are you working with?
We are using Ubuntu 20.04.2 LTS and Node 12.13.1
I would recommend that you use the LTS version of node (16).
Or instead of running it locally you could prepare a docker image that contains the following
# Install linux dependencies RUN apt-get update \ && apt-get install -y \ gconf-service \ libasound2 \ libatk1.0-0 \ libatk-bridge2.0-0 \ libc6 \ libcairo2 \ libcups2 \ libdbus-1-3 \ libexpat1 \ libfontconfig1 \ libgcc1 \ libgconf-2-4 \ libgdk-pixbuf2.0-0 \ libglib2.0-0 \ libgtk-3-0 \ libnspr4 \ libpango-1.0-0 \ libpangocairo-1.0-0 \ libstdc++6 \ libx11-6 \ libx11-xcb1 \ libxcb1 \ libxcomposite1 \ libxcursor1 \ libxdamage1 \ libxext6 \ libxfixes3 \ libxi6 \ libxrandr2 \ libxrender1 \ libxss1 \ libxtst6 \ ca-certificates \ fonts-liberation \ libappindicator1 \ libnss3 \ lsb-release \ xdg-utils \ wget \ libgbm-dev \ && npm i puppeteer nodemon
This will allow you to run a container with the application regardless of the OS version you have.
Ok I will try the first solution. Second option is not possible with our current working environment.
Did you solve this problem?? I installed all the dependencies that were listed as not found within node_modules puppeter. I'm using node v17.4.0 and still the process of creating the pdf just hags out and nothing is loggued .
EDIT: It's probably just an issue with puppeteer version, this library uses an old version- 10.4.0
Had the same issue, Windows was working great, but ubuntu returned nothing. I managed to solve it by incorporating the library's code into my project.
I installed these libraries seperately(running npm install on ubuntu produced an error while installing puppeteer):
const puppeteer = require('puppeteer'); var Promise = require('bluebird'); const hb = require('handlebars'); const inlineCss = require('inline-css');
And the actual PDF creation: ` async generatePdf(file, options, callback) {
let args = ['--no-sandbox', '--disable-setuid-sandbox'];
if (options.args) {
args = options.args;
delete options.args;
}
const browser = await puppeteer.launch({
args: args,
});
const page = await browser.newPage();
if (file.content) {
const data = await inlineCss(file.content, { url: '/' });
console.log('Compiling the template with handlebars');
// we have compile our code with handlebars
const template = hb.compile(data, { strict: true });
const result = template(data);
const html = result;// We set the page content as the generated html by handlebars
await page.setContent(html, {
waitUntil: 'networkidle0', // wait for page to load completely
});
} else {
await page.goto(file.url, {
waitUntil: ['load', 'networkidle0'], // wait for page to load completely
});
}
return Promise.props(page.pdf(options))
.then(async function (data) {
await browser.close();
return Buffer.from(Object.values(data));
})
.asCallback(callback);
}`
HTML to PDF conversion not working with Ubuntu 20.04.2 LTS We are using Ubuntu 20.04.2 LTS and NodeJS v12.13.1 This function not producing any output or error messages html_to_pdf.generatePdf
But at the same time this combination works well Ubuntu 18 and NodeJS v12.13.1
Any help appreciated. Thanks