K
kpowell10
Hello all,
I'm trying to go through a folder full of Words docs and create a PDF
doc for each of them using WIN32::OLE. The problem I'm having is that
I can't get the "FileName" line to work so that I can automate the
naming of the files.
Here's the code:
*************************************************************
use Cwd 'abs_path';
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';
my $Word = Win32::OLE->new('Word.Application', 'Quit');
$Word->{'Visible'} = 0;
$Word->{ActivePrinter} = 'Acrobat PDFWriter on LPT1:';
$dirname = abs_path($ENV{'PWD'});
#### Fill @files with the names of every file
opendir(DIR, $dirname) or die("unable opendir $dirname: $!");
while (defined($file = readdir(DIR))){
if ($file =~/.doc$/i){
push(@files,$file);
}
}
#### For each file in the folder (inside @files),
#### if it's a Word doc, print it to a PDF file
foreach $file (@files){
if ($file =~/.doc$/i){
$fullfile="$dirname\\$file";
$_ = $fullfile;
s/doc$//;
$newfile=$_;
print "Word doc - $fullfile\n";
$Word->Documents->Open($fullfile) or die("Can't access file ",
Win32::OLE->LastError());
$Word->ActiveDocument->PrintOut({
#### Here's the problem - if I comment out the line below,
#### it will print, but prompts for a file name. If
#### the 'Filename' line exists at all, it doesn't
#### print out the pdf file. I want this automated
#### so I'm not prompted for the filename.
#'FileName' => '$fullfule.pdf',
});
$Word->ActiveDocument->Close;
}
}
*************************************************************
If I haven't included enough information, please let me know. Thanks
in advance,
Kyle
I'm trying to go through a folder full of Words docs and create a PDF
doc for each of them using WIN32::OLE. The problem I'm having is that
I can't get the "FileName" line to work so that I can automate the
naming of the files.
Here's the code:
*************************************************************
use Cwd 'abs_path';
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';
my $Word = Win32::OLE->new('Word.Application', 'Quit');
$Word->{'Visible'} = 0;
$Word->{ActivePrinter} = 'Acrobat PDFWriter on LPT1:';
$dirname = abs_path($ENV{'PWD'});
#### Fill @files with the names of every file
opendir(DIR, $dirname) or die("unable opendir $dirname: $!");
while (defined($file = readdir(DIR))){
if ($file =~/.doc$/i){
push(@files,$file);
}
}
#### For each file in the folder (inside @files),
#### if it's a Word doc, print it to a PDF file
foreach $file (@files){
if ($file =~/.doc$/i){
$fullfile="$dirname\\$file";
$_ = $fullfile;
s/doc$//;
$newfile=$_;
print "Word doc - $fullfile\n";
$Word->Documents->Open($fullfile) or die("Can't access file ",
Win32::OLE->LastError());
$Word->ActiveDocument->PrintOut({
#### Here's the problem - if I comment out the line below,
#### it will print, but prompts for a file name. If
#### the 'Filename' line exists at all, it doesn't
#### print out the pdf file. I want this automated
#### so I'm not prompted for the filename.
#'FileName' => '$fullfule.pdf',
});
$Word->ActiveDocument->Close;
}
}
*************************************************************
If I haven't included enough information, please let me know. Thanks
in advance,
Kyle