Printing PDF files using Win32::OLE and Acrobat Exchange

Discussion in 'Perl Misc' started by Domenico Discepola, Jul 15, 2004.

  1. Hello. My goal is to print Adobe PDF files from a Perl script without any
    user intervention. I have been experimenting with various methods and am
    now trying to use Win32::OLE to control Adobe Acrobat Exchange (v5.0.5).
    Please refer to the code below. I can create the acrobat object, open the
    document and retrieve some information from the document. My problems are:

    1. Although I make acrobat visible using the show method, only the
    application becomes visible, not the document. How do I fix this?

    2. What is the method to print the document once it has been opened? The
    "PrintPagesEx" method produces an error "Win32::OLE 0.1701) error
    0x80020003: "Member not found" in METHOD/PROPERTYGET "" at jps2.pl line 30".
    I then tried to loop through the hash referenced by the $doc variable but no
    output from the hash was printed.

    3. As an aside, if someone can provide me with the class name for Acrobat
    Reader (not Acrobat exchange, as I have coded below) that would be great (or
    inform me how to find it). I am relatively inexperienced in the world of
    OLE Automation so any hints would be helpful.


    ##############
    #!perl
    use strict;
    use warnings;
    use diagnostics;
    use Win32::OLE;
    use Win32::OLE::Const "Acrobat";
    our $g_file_input = shift @ARGV;
    die "Usage: $0 filename\n" unless $g_file_input;

    sub process_main {
    my $acrobat = Win32::OLE->new("AcroExch.App","Quit");
    my $doc = Win32::OLE->new("AcroExch.PDDoc");
    $doc->Open( ${g_file_input} ) or die("Could not open $g_file_input: $!\n");
    $acrobat->show;
    print "Title=",$doc->GetInfo("Title"),"\n\n";

    #This does not work

    #$doc->PrintPagesEx(1,5,2,'True','True','False','True','True','PDAllPages');

    }

    sub main {
    print "PDF program\n";
    &process_main();
    print "Ending now\n";
    }

    &main();
    exit 0;
    ###############
    Domenico Discepola, Jul 15, 2004
    #1
    1. Advertising

  2. Domenico Discepola

    Matt Garrish Guest

    "Domenico Discepola" <> wrote in
    message news:BpAJc.26617$...
    >
    > 3. As an aside, if someone can provide me with the class name for Acrobat
    > Reader (not Acrobat exchange, as I have coded below) that would be great

    (or
    > inform me how to find it). I am relatively inexperienced in the world of
    > OLE Automation so any hints would be helpful.
    >


    4.1 Differences Among the Acrobat Viewers

    Acrobat supports all of the OLE automation methods
    listed in this chapter.

    The Acrobat Reader does not support OLE automation.


    For more info: http://partners.adobe.com/asn/acrobat/docs/iacovr.pdf

    (And I don't have Exchange, so I can't help you with the rest.)

    Matt
    Matt Garrish, Jul 16, 2004
    #2
    1. Advertising

  3. "Matt Garrish" <> wrote in message
    news:6EEJc.26179$...
    >
    > Acrobat supports all of the OLE automation methods
    > listed in this chapter.
    >
    > The Acrobat Reader does not support OLE automation.
    >
    >
    > For more info: http://partners.adobe.com/asn/acrobat/docs/iacovr.pdf
    >


    Success! Here is the code that opens up and prints a PDF using Win32::OLE
    and Acrobat Exchange (v5.0.5 is the version I have). Thanks for the link to
    Acrobat Exchange's OLE Objects and Methods. Too bad that Acrobat Reader
    doesn't support OLE automation - I'm sure more people could have benefited
    from this.

    ######################
    #!perl
    use strict;
    use warnings;
    use diagnostics;
    use Win32::OLE;
    use Win32::OLE::Const "Acrobat";
    our $g_file_input = shift @ARGV;
    die "Usage: $0 filename\n" unless $g_file_input;

    sub process_main {
    my $acrobat = Win32::OLE->new("AcroExch.App", "Quit");
    my $avdoc = Win32::OLE->new("AcroExch.AVDoc");
    $avdoc->Open( $g_file_input, "" );
    my $pddoc = Win32::OLE->new("AcroExch.PDDoc");
    $pddoc->Open( $g_file_input);
    my $pp = $pddoc->GetNumPages; #index starts at 0
    if ( $pp ) {
    $pp--;
    }
    print "Num pages: $pp\n";
    $avdoc->PrintPagesSilent(0,$pp,1,1,0);
    $acrobat->Exit;
    }

    sub main {
    print "PDF program\n";
    &process_main();
    print "Ending now\n";
    }

    &main();
    exit 0;
    Domenico Discepola, Jul 16, 2004
    #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. kbperry
    Replies:
    13
    Views:
    1,275
    kbperry
    Mar 31, 2006
  2. Dinil Karun

    Convert Word .doc to Acrobat .pdf files

    Dinil Karun, Jun 6, 2008, in forum: Python
    Replies:
    0
    Views:
    623
    Dinil Karun
    Jun 6, 2008
  3. Martin
    Replies:
    1
    Views:
    269
    Bullschmidt
    Oct 5, 2005
  4. kpowell10
    Replies:
    2
    Views:
    172
    Jay Tilton
    Jul 9, 2003
  5. Lance Hoffmeyer
    Replies:
    0
    Views:
    238
    Lance Hoffmeyer
    Nov 17, 2003
Loading...

Share This Page