#!/usr/bin/perl #### takes string containing HTML and outputs PDF to browser to download #### (otherwise would output to STDOUT) print "Content-Disposition: attachment; filename='testPDF.pdf'\n"; print "Content-type: application/octet-stream\n\n"; my $htmlToPrint = "a bunch of html"; ### open a filehandle and pipe it to wkhtmltopdf ### *the arguments "- -" tell wkhtmltopdf to get ### input from STDIN and send output to STDOUT* open(my $makePDF, "|-", "/usr/local/bin/wkhtmltopdf", "-", "-") || die("$!"); print $makePDF $htmlToPrint; ## sends my HTML to wkhtmltopdf which streams immediately to STDOUT