WIN32::OLE - Printing a PDF document from Windows

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
 
W

William Alexander Segraves

kpowell10 said:
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:
*************************************************************
#'FileName' => '$fullfule.pdf',

What was the error message you received on account of your typo above? I
believe you meant, even though it was incorrect,

'FileName' => '$fullfile.pdf',

which appears to be legal Perl syntax, but does not work because $fullfile
is not evaluated. Try using the correct attribute for PrintOut, i.e.,

OutputFileName => "fullfile.pdf",

If I haven't included enough information, please let me know. Thanks
in advance,

Kyle, you might try a Google Groups search for "win32::eek:le acrobat dorey",
where you'll find some helpful information.

One of the difficulties you'll have is that this is not really a Perl
problem, as legal Perl code may fail for reasons not related to Perl.

Good luck.

Bill Segraves
 
J

Jay Tilton

(e-mail address removed) (kpowell10) wrote:

: 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.

[snip]

: $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',
: });

There wasn't a solution handy the last time this was asked.
See Message-ID: <[email protected]>

The OP did take the advice given, though. He got what looks like a
reasonable answer in microsoft.public.vb.ole.automation, but there's
no evident followup saying whether it worked.
See the thread starting at
Message-ID: <566501c2bbda$d67a5040$8af82ecf@TK2MSFTNGXA03> .

The API reference would be useful.
http://partners.adobe.com/asn/acrobat/docs/createpdfapi/PDFWriterAPIReference.pdf

It mentions some jive about a registry key that will suppress the
dialog box. That sounds like the real solution.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top