beganovich / snappdf

Convert webpages or HTML into the PDF file using Chromium-powered browsers.
MIT License
188 stars 15 forks source link

Errors with chrome on Ubuntu 20.04 and some possible fixes #43

Open robwent opened 3 months ago

robwent commented 3 months ago

I got this working on my local Windows machine, but after uploading to my live site, I was getting an unhelpful Symfony error:

The process has been signalled with signal "6"

I installed all the mentioned packages but couldn't get past this.

I then downloaded a separate copy of Chrome to see if that was the issue, but I still got the same error. Trying to run it on the command line, I got a permission error, so chowned the main chrome file to 755 and then got an error:

[2543468:2543468:0708/213831.722702:ERROR:ozone_platform_x11.cc(244)] Missing X server or $DISPLAY
[2543468:2543468:0708/213831.722895:ERROR:env.cc(258)] The platform failed to initialize.  Exiting.

I found some threads about Chrome not being able to find a default display and running printenv DISPLAY showed nothing. I then found this thread https://github.com/puppeteer/puppeteer/issues/8148#issuecomment-1397528849 Ran

apt-get install xvfb x11-apps x11-xkb-utils libx11-6 libx11-xcb1
Xvfb -ac :99 -screen 0 1280x1024x16 & export DISPLAY=:99

After that, running printenv DISPLAY outputs: :99

At that point, I could generate a PDF by using the copy of Chrome I uploaded, but not the one downloaded by the download command (I ran it separately on each machine originally).

Unfortunately, I can't remember where I downloaded Chrome from manually, but it doesn't seem to be an official version. The filename is ungoogled-chromium_126.0.6478.127_1.vaapi_linux.tar.xz

Hopefully, this might help someone else get it working.

turbo124 commented 3 months ago

@beganovich this is a widespread issue I think may be related to the newer version of snapped. I am also seeing that if attempting to use a dedicated path to a separate chrome binary, this is not being respected by snappdf

robwent commented 3 months ago

The path to binary is working for me as I have it set on the live site but not the local one. $snappdf->setChromiumPath( '/my/path/chrome' );

I just tested command line and got the same signal "6" error, but if I set the --binary flag then it works.

I was previously using hosted_ninja for pdfs on another server, but switched that to snappdf today as the servers were a similar setup (that one is Ubuntu 22.04). That one worked straight away without installing any new packages, but the binary was already downloaded. I didn't force a new download so it could be an older version.

On another note, I couldn't get any flags working like width & height, removing margins and making landscape. I got that working by setting @page in CSS like dompdf:

@page {
            size: 11in 8.5in;
            margin: 0;
        }
beganovich commented 3 months ago

Thanks, guys, I'll tinker on this one soon.

beganovich commented 3 months ago

@robwent can you try adding 0755 to chrome_crashpad_handler too?

You can find it in vendor/beganovich/snappdf/versions and find folder where chrome is. There should be chrome_crashpad_handler too.

chmod 0755 chrome_crashpad_handler