use strict; use CGI::Carp 'fatalsToBrowser'; print "Content-Type: text/plain\n\n"; # Change to the directory where I want the final output # stored (this seems to help antiword work correctly) chdir('/path/to/my/pdfs') or die "Couldn't change directory: $!\n"; # Antiword only outputs to STDOUT so I just decided to use # backticks to capture the output. In the real program I # check and make sure no one is doing anything funny with # the filename my $postscript = `/usr/local/bin/antiword -m 8859-1.txt -p letter /tmp/worddoc.doc`; # since more than one person could be working on this at # a single time make sure we have a unique name for the # temp file my $tmpfile = ""; my $count = 0; { $tmpfile = "pdftmp$count.ps"; $count++; redo if -e "/tmp/$tmpfile"; } # save the postscript to the temp file open(TMPFILE,">/tmp/$tmpfile") or die "Couldn't open $tmpfile: $!\n"; print TMPFILE $postscript; close(TMPFILE); # Convert the Postscript to pdf (here's where we choke) system("/usr/local/bin/ps2pdf","/tmp/$tmpfile","test.pdf") == 0 or die $? >> 8; print "Done\n";