Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Printing PDF files using Win32::OLE and Acrobat Exchange

Reply
Thread Tools

Printing PDF files using Win32::OLE and Acrobat Exchange

 
 
Domenico Discepola
Guest
Posts: n/a
 
      07-15-2004
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;
###############


 
Reply With Quote
 
 
 
 
Matt Garrish
Guest
Posts: n/a
 
      07-15-2004

"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


 
Reply With Quote
 
 
 
 
Domenico Discepola
Guest
Posts: n/a
 
      07-16-2004

"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;


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Print content of an ASP page to acrobat PDF destiller and send PDF to browser Martin ASP General 1 10-05-2005 09:57 PM
Acrobat 6 or Acrobat 7 driver installation problem =?Utf-8?B?SmltSVQ=?= Windows 64bit 4 06-24-2005 03:59 PM
How to open pdf Adobe Acrobat files protected by FileOpen? JD Computer Support 0 06-11-2004 11:44 PM
How to attach serial number to Acrobat .pdf files for security? JD Computer Support 5 06-05-2004 10:02 AM
Adobe Acrobat files .PDF Dave Croft Computer Support 2 02-19-2004 02:48 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57