Skip to content

Building font file via shell script

Libor M edited this page Aug 4, 2018 · 9 revisions

If you don't want to install gulp and/or just downloaded pdfMake and want to use custom fonts in client-side, you can generate the vfs_fonts.js with an bash-script as well:

#!/bin/sh

if [ -t 1 ]; then
	target="vfs_fonts.js"
else
	target="/dev/stdout"
fi

(
	echo -n "this.pdfMake = this.pdfMake || {}; this.pdfMake.vfs = {"
	for file in "$@"; do
		file=$1
		shift
		echo -n '"'
		echo -n "$(basename $file)"
		echo -n '":"'
		echo -n "$(base64 -w 0 $file)"
		echo -n '"'
		if [ "$#" -gt 0 ]; then
			echo -n ","
		fi
	done
	echo -n "};"
) > "$target"
Clone this wiki locally