use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; use Getopt::Std; my %opts; getopts('o:i:', \%opts); my $infile = $opts{i} || die "No input File specified - use -i file\n"; my $outfile = $opts{o} || die "No output File specified - use -o file\n"; my $Word = Win32::OLE->new('Word.Application', 'Quit'); # $Word->{'Visible'} = 1; # if you want to see what's going on $Word->Documents->Open($infile) || die("Unable to open document ", Win32::OLE->LastError()); $Word->{DisplayAlerts}=-1; $Word->ActiveDocument->PrintOut({ Background => 0, Append => 0, Range => wdPrintAllDocument, Item => wdPrintDocumentContent, Copies => 1, PageType => wdPrintAllPages, OutputFileName => $outfile, PrintToFile => 1, }); $Word->ActiveDocument->Close(0); unlink $outfile; #The pdf creation appends ".pdf" to $outfile, but creates an empty $outfile as well