Presenting HTML to PDF custom module. This extension adds to the already great set of components Wappler provided by default. Its available for both PHP and NodeJS server models.
Add HTML to PDF step in server connect from File Management category, specify an output folder path & name along with your custom HTML and the module will create a PDF from that HTML and save it.
You can then use that PDF to send as attachment via email or just store the path in DB.
For NodeJS, you will have to install 1 package - Puppeteer.
This package has its own set of dependencies and might not work on a shared hosting server.
For PHP, you will have to install 1 package - mPDF using Composer.
This package is not as powerful as NodeJS’s puppeteer, ref here.
For details on how to integrate custom modules in your Wappler project, please refer the help doc here.
I nominate you for an award @sid We know the team is so so busy with “requests” … and they do their best to get everything done… its a mammoth task…
Im sure everybody that wanted a HTML to PDF solution within Wappler is grateful for your contribution. Thank you.
I think there was like Pdf generator/export 54 votes. I will also post your link in there … if you dont mind…
And sorry for a noob question. Do I install it from terminal using NPM and that's it or I must include the dependency into the public folder and then manually include the link from the main page.
I would be very interested in a tool that works the other way around and converts pdf file content to html.
Could you help me along to develop a custom module for this? Thank you very much for your help in advance!
Failed to launch the browser process!
/opt/node_app/node_modules/puppeteer/.local-chromium/linux-869685/chrome-linux/chrome: error while loading shared libraries: libgobject-2.0.so.0: cannot open shared object file: No such file or directory
Like it says on the SO link, it was the positioning on apt-get that was the cause of issue.
You need to install some packages separately in docker to get puppeteer to run.
The docker.yml file is the one you need to setup I think to write those apt-get commands. Not sure though.
Basically, I copied inside the dockerfile this code:
FROM node:12-slim
# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
RUN apt-get update \
&& apt-get install -y wget gnupg \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
# If running Docker >= 1.13.0 use docker run's --init arg to reap zombie processes, otherwise
# uncomment the following lines to have `dumb-init` as PID 1
# ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_x86_64 /usr/local/bin/dumb-init
# RUN chmod +x /usr/local/bin/dumb-init
# ENTRYPOINT ["dumb-init", "--"]
# Uncomment to skip the chromium download when installing puppeteer. If you do,
# you'll need to launch puppeteer with:
# browser.launch({executablePath: 'google-chrome-stable'})
# ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
# Install puppeteer so it's available in the container.
RUN npm i puppeteer \
# Add user so we don't need --no-sandbox.
# same layer as npm install to keep re-chowned files from using up several hundred MBs more space
&& groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
&& mkdir -p /home/pptruser/Downloads \
&& chown -R pptruser:pptruser /home/pptruser \
&& chown -R pptruser:pptruser /node_modules
# Run everything after as non-privileged user.
USER pptruser
CMD ["google-chrome-stable"]
But after deploying and starting Docker, I’m getting this new error I can’t solve:
Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted
I’m quite lost. My complete docker file is the original that Wappler creates automatically when you start a new proyect with those lines I previously copied (I’m not with my Mac right now).
After 4 hours of research, I gave up. I really don’t know how to implement the chromium and puppeteer service on the same image that runs Wappler’s web app. Maybe I should create a new image with those two services? There’s documentation and proyects to clone where you can start a Docker machine runing those services. But from what I understand, that won’t work because it would be separated from the web app, right?
Hello once again. Now with my server working with Puppeteer I wanted to know if there is any way I could use wappler’s frameworks for styling the PDF or I should do it manually?
I wanted to use these frameworks but the action crashes when executing it:
The paths all need to be absolute.
So for jQuery, you cannot use .. /js/
Replace that with a CDN URL. Or even a full URL from your own deployed project.