package RequestForm::PDF; use Moo; use IO::All; use Data::Dumper; use File::Temp qw(tempfile); use Local::MooX::Types qw(String); has content => ( is => 'ro', isa => String, required => 1 ); sub render { my $content = shift->content; # warn Dumper $content; # create temp file for input to wkhtmltopdf (default is to UNLINK): my $tmp_file = File::Temp->new(SUFFIX => '.html', UNLINK => 1); # warn $tmp_file; io($tmp_file->filename)->print($content); # save file to disk my @args = ( '--margin-top 3', ); my $pdf = `/usr/local/bin/wkhtmltopdf -q @args $tmp_file -`; return $pdf; # not required if using File::Temp OO interface (destroy is automatic): if ( -e $tmp_file ) { io($tmp_file)->unlink or warn "could not unlink $tmp_file: $!"; } } 1;