sub printFilePdf { my $unique_id = shift; my ($file) = "$OUTFILES/$unique_id.html"; open(my $htmlFH, '<', $file) or die "Can't open file $file $!\n"; my $processId = open2(\*POUT, \*PIN, qq(html2ps -U -f /home/apache/cgi-bin/test/html2psrc-tst)); my @lines = <$htmlFH>; print PIN @lines; close PIN; my @psLines; while () { chomp; push(@psLines,$_); } waitpid $processId, 0; $processId = open2(\*POUT, \*PIN, qq(ps2pdf -sPAPERSIZE=letter - -)); print PIN "$_\n" foreach(@psLines); close PIN; my @pdfLines; while () { chomp; push(@pdfLines, $_); } waitpid $processId, 0; #I am thinking right about here print "Content-Type: application/pdf\n"; print "Content-Disposition: attachment; filename=record.pdf\n\n"; print "$_\n" foreach(@pdfLines); }