Open shankie-codes opened 7 years ago
Oops I think that this might be to me not initializing Xvfb... will report back
On a side note, what is the use case for doing this? (connecting into a running container and installing "stuff")? Wouldn't it be better to create a Dockerfile and build your own image with electron-pdf included?
Yeah, it was just a quick and dirty. I was just hacking around trying to see what worked and what didn't without building again – the plan was to put it in a Dockerfile once I worked out what was going on.
The problem was definitely to do with Xvfb not being configured correctly. Could probably do with some more useful error messages in that case. I'll have a quick look tomorrow and see if I can figure out a solution
I can't make it work on my headless Debian instances. I just followed the readme to init Xvfb but still getting the "Electron failed to install correctly" error... any ideas?
Hmm from memory, I think that this was resolved (for me anyways) from a PR that someone else merged...
I'm trying this on electron-pdf v1.3.0 that's the latest version right now
I had this problem as well on a fresh install on Ubuntu 18.04 with Node v8.10.0 and NPM 3.5.2.
I got it working by installing some additional packages and running electron/install.js after installing electron-pdf, see below:
$ sudo apt-get install xvfb xorg openbox libgtkextra-dev libgconf2-dev libnss3 libasound2 libxtst-dev libxss1 libxtst6 libgtk2.0-0
$ sudo npm install electron-pdf --global
$ cd /usr/local/lib/node_modules/electron-pdf/node_modules/electron/ && node install.js
$ sudo apt-get install xvfb # or equivalent
$ export DISPLAY=':99.0'
$ Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
Then you it works on command line e.g.
$ electron-pdf http://mysite/file.html /tmp/output.pdf
Thanks @colinwoods, I don't know why I didn't share this earlier, but this is how I have my image configured.
FROM ubuntu:18.04
WORKDIR /app
RUN apt-get update && \
apt-get install -y \
# v8 comes from apt
nodejs npm \
# Required for Headless Electron/Chromium Rendering
libgconf2-4 libxss1 libxtst6 libnss3 libasound2 xvfb dbus-x11 libgtk2.0-common \
# Get rid of files we don't need
rm -rf /var/lib/apt/lists/* && \
# Get latest npm
npm install -g npm
And while not required if only using electron-pdf I also use these packages (which may pull in other dependencies)
# Required for PDF -> PNG Conversion
mupdf-tools \
# Used for PDF->PNG splitting by pdf2images-multiple
poppler-utils && \
I used this package about six months ago without issue, but later versions (will report back with a since) seem to have the following error:
Error: Electron failed to install correctly, please delete node_modules/electron and try installing again
Quick test case:
docker run --rm -it --name test kipparker/docker-tape-run sleep 1000000
(just to get a quick test container up that has all the deps)Connect into the container and
npm install -g electron-pdf
. Run anelectron-pdf
command, such aselectron-pdf http://example.com ~/test.pdf
Results in something like: