1

i have installed browsershot in my laravel project I have installed puppeteer, installed chromium , my npm version is updated, but still i am unable to get the PDF of my simple html input , i have tried to take screenshot by URL method and save as image(It works), but my requirement is to generate PDF of my html.

This is my code in controller

$output=Browsershot::html($html)
->setNodeModulePath("/var/www/html/ProjectName/node_modules/")
->setChromePath("/usr/bin/chromium-browser") 
    ->setNodeBinary('/usr/local/bin/node')
    ->setNpmBinary('/usr/local/bin/npm')
->showBackground()
->noSandbox()->timeout(60)
->save(public_path("DevTest.pdf");          

Error Message:

"message": "The process "PATH=$PATH:/usr/local/bin NODE_PATH='/var/www/html/ProjectName/node_modules/' /usr/local/bin/node '/var/www/html/benesprint/vendor/spatie/browsershot/src/../bin/browser.js' '{"url":"file:\/\/\/tmp\/1933874416-0068512001600765779\/index.html","action":"pdf","options":{"path":"\/var\/www\/html\/ProjectName\/public\/DevTest.pdf","args":["--no-sandbox"],"viewport":{"width":800,"height":600},"displayHeaderFooter":false,"executablePath":"\/usr\/bin\/chromium-browser","timeout":60000,"printBackground":true}}'" exceeded the timeout of 60 seconds.",

**i would be grateful if you can help me out.**
apokryfos
  • 38,771
  • 9
  • 70
  • 114
  • i guess you should increase `->timeout(120)` or somthing – Kamlesh Paul Sep 22 '20 at 09:31
  • i have used simple

    Test

    , instead of passing my complete html variable , it works , but i need to render my complete blade into that pdf, $html = view('MyBlade',compact('result'))->render();
    – Syed Hassaan Anwer Sep 22 '20 at 09:35
  • i have got to the real issue, basically i have included bootstrap and jquery into that blade file , when i remove them , it works but if i kept them all along for UI designing the issue occurs again. – Syed Hassaan Anwer Sep 22 '20 at 09:50

1 Answers1

0

i have similiar problem when browsershot inside container. and my step to resolve is like this:

  1. Manual generate PDF from html using laravel tinker. if there is an error, try reinstall chromium and puppeteer library.
  2. If success, then try remove all css and javascript links from html, and check for the result.
  3. If success, then add --proxy-server="direct://" and --proxy-bypass-list=* into browsershot args
  4. If step 3 is not working, then you can put css and javascript directly into view template or using php code to inclue those files like
   <?php include public_path('css/styles.css') ?>
coda
  • 1
  • 1