WIN32::OLE - Printing a PDF document from Windows

Discussion in 'Perl Misc' started by kpowell10, Jul 9, 2003.

  1. kpowell10

    kpowell10 Guest

    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
     
    kpowell10, Jul 9, 2003
    #1
    1. Advertising

  2. "kpowell10" <> wrote in message
    news:...
    > 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:
    > *************************************************************

    <snip>
    > #'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",

    <snip>
    > 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
     
    William Alexander Segraves, Jul 9, 2003
    #2
    1. Advertising

  3. kpowell10

    Jay Tilton Guest

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

    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.
     
    Jay Tilton, Jul 9, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick.O.Ige

    Ole ole

    Patrick.O.Ige, Jul 16, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    509
    Patrick.O.Ige
    Jul 16, 2006
  2. Drew Pihera
    Replies:
    0
    Views:
    656
    Drew Pihera
    Feb 4, 2004
  3. Lance Hoffmeyer
    Replies:
    0
    Views:
    253
    Lance Hoffmeyer
    Nov 17, 2003
  4. Domenico Discepola
    Replies:
    2
    Views:
    650
    Domenico Discepola
    Jul 16, 2004
  5. deepakp
    Replies:
    1
    Views:
    727
    A. Sinan Unur
    Mar 3, 2006
Loading...

Share This Page