A few months ago, James Moberg listed out a good number of Command-Line utilities that he uses in ColdFusion. Among them is wkhtmltopdf, which is a tool that can convert HTML and CSS to PDFs using the Qt WebKit rendering engine. Since I’ve been digging into PDF document generation in Lucee CFML, with varying degrees of success, I thought it was time that I try out Moberg’s wkhtmltopdf recommendation. As such, this weekend, I sat down and got a proof-of-concept working in Docker and Lucee CFML 5.3.4.80.

Setting Up My Docker Container / Playground

Just as with my GraphicsMagick exploration in Lucee CFML, I figured that the cleanest way to start playing with wkhtmltopdf would be to create a Docker container that isolates this work and allows me to easily spin-up and spin-down my experiments. And, as with my GraphicsMagick approach, my Docker container is based on the Ortus Solutions’ CommandBox Docker Image for Lucee CFML 5.

The wkhtmltopdf project provides a number of pre-compiled binaries for different platforms. But, I didn’t know which platform the CommandBox image was actually running on - honestly, I know very little about Servers themselves. So, I had to figure out what platform I was running on first.

Based on a StackExchange post, I learned that I could run lsb_release -a to see what distribution I was using. So, my first Dockerfile did nothing but spin-up the CommandBox base image, which I could then “bash” into and run the aforementioned command. This gave me the following terminal output:

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.4 LTS
Release:	18.04
Codename:	bionic

Given this information, I was able to see that I needed to use the Ubuntu 18.04 (bionic) version with CommandBox. Now, I don’t really understand the difference between “architectures”; so, I just picked the first one - amd64 - and that turned out to be correct.

Then, I more-or-less copied the wkhtmltopdf Docker instructions from Deyan Ginev, which gave me the following Dockerfile:


   # Use the CommandBox base image.
	FROM ortussolutions/commandbox:lucee5

	# Prevents the keyboard from having to be configured during build.
	# --
	# Read more: https://github.com/phusion/baseimage-docker/issues/342
	ENV DEBIAN_FRONTEND noninteractive

	# CAUTION: The following dependencies list and installation steps have been taken from:
	# --
	# https://github.com/openlabs/docker-wkhtmltopdf/blob/master/Dockerfile
	# --
	# ... and modified slightly. I am not sure if the dependencies listed her are actually
	# required. Frankly, I don't even know how to determine which dependencies a package like
	# wkhtmltopdf even requires.
	RUN apt-get update
	RUN apt-get upgrade -y

	# Download and install wkhtmltopdf dependencies.
	RUN apt-get install -y \
		build-essential \
		xorg \
		libssl-dev \
		libxrender-dev \
		wget \
		gdebi \
		&& apt-get clean

	# Download the wkhtmltopdf package.
	RUN wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.bionic_amd64.deb

	# Install the wkhtmltopdf package.
	RUN gdebi --n wkhtmltox_0.12.6-1.bionic_amd64.deb

#coldfusion #docker #lucee cfml 5.3.4.80 #wkhtmltopdf 0.12.6 #commandbox

Testing wkhtmltopdf 0.12.6 With Docker In Lucee CFML 5.3.4.80
14.40 GEEK