hajareshyam / pdf-creator-node

This package is used to generate HTML to PDF in Nodejs
MIT License
238 stars 79 forks source link

Working local but not working in server #100

Open drilonpa opened 1 year ago

drilonpa commented 1 year ago

Error: spawn /home/node/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs ENOENT at Process.ChildProcess._handle.onexit (node:internal/child_process:285:19) at onErrorNT (node:internal/child_process:485:16) at processTicksAndRejections (node:internal/process/task_queues:83:21) { errno: -2, code: 'ENOENT', syscall: 'spawn /home/node/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs', path: '/home/node/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs', spawnargs: [ '--local-url-access=false', '/home/node/node_modules/html-pdf/lib/scripts/pdf_a4_portrait.js' ] }

XXXL3J commented 1 year ago

Try reinstall the latest version

Shaxadhere commented 1 year ago

Maybe this is because it uses headless chrome and your server does not have chrome installed even if it's installed maybe it cannot find the path to chrome on the server. I had a similar issue using puppeteer and I fixed it by installing chrome on the server and giving it the path to chrome.

vignesh291999 commented 1 year ago

Same issue here also I am using pdf-creator-node

const document = { html: html, data: data, path: '', type: 'buffer', };

  const created = await pdf.create(document, options);
  res.setHeader('Content-disposition', `attachment; filename="${downloadFile}"`);
  res.setHeader('Content-Type', 'application/pdf');
  res.end(created);
}

locally its working fine pdf is generating in download folder but when hosted in Azure its not working as expected...

TilliSp commented 11 months ago

Та же проблема здесь, я использую pdf-creator-node

const document = { html: html, data: data, path: '', type: 'buffer', };

  const created = await pdf.create(document, options);
  res.setHeader('Content-disposition', `attachment; filename="${downloadFile}"`);
  res.setHeader('Content-Type', 'application/pdf');
  res.end(created);
}

локально его работающий PDF-файл генерируется в папке загрузки, но при размещении в Azure он не работает должным образом...

@vignesh291999 were you able to solve the problem?

drilonpa commented 11 months ago

I have fixed this issues

Just try to install chromium in Cloud Servers

TilliSp commented 11 months ago

@drilonpa What do you mean? Chrome driver or ...what? Sorry, I`m new to this (:

junaidranjha commented 11 months ago

@TilliSp did you find any solution?

gregg-cbs commented 11 months ago

Ahh the reason this does not work when being deployed to any platform is that this package is using 'html-pdf' which is a development only library - all its dependencies are devDependencies.

So when you deploy to production none of its dependencies get installed.

This is really poor decision making from @hajareshyam who used that package. It actually seems that this author has never used this package in production.

Furthermore html-pdf package is deprecated along with all its dependencies. I would imagine this package to be slow and resource intensive because it is using phantomjs which is a headless browser.

The author should do us a favour and remove this package from github and npm because this has become a massive waste of time.

drilonpa commented 11 months ago

@TilliSp Based on your OS system in cloud server you need to install https://www.chromium.org/getting-involved/download-chromium/