#!perl -w use strict; use warnings; use Win32::GUI 1.06 qw(CW_USEDEFAULT); use Win32::GUI::AxWindow; # Define the application menu my @menu_defn = ( "File" => "File", ">OpenPDf" => { -name => "OpenPDF", -onClick => \&OpenPDF}, ">Exit" => { -name => "Exit", -onClick => sub{-1}, }, ); my $menu = Win32::GUI::Menu->new(@menu_defn); #Define the application window my $mw = Win32::GUI::Window->new( -title => "Open PDF File", -size => [400,400], -left => CW_USEDEFAULT, -menu => $menu, -onResize => \&resize, -onTerminate => \&QuitFile, ); # Add a Acrobat AxtiveX control my $PDFControl = new Win32::GUI::AxWindow ( -parent => $mw, -name => "PDFControl", -control => "AcroPDF.PDF.1", -pos => [0, 0], -size => [400, 400], ); #Show application window $mw->Show(); #Enter event loop Win32::GUI::Dialog(); #Hide windows on exit $mw->Hide(); undef $mw; exit(0); #Open standard windows file open dialog box sub OpenPDF { my ( @file, $file ); my ( @parms ); push @parms, -filter => [ 'PDF - Adobe Acrobat File', '*.pdf', ], -directory => "c:\\", -title => 'Select a PDF file'; @file = Win32::GUI::GetOpenFileName ( @parms ); # print "PDF File: $file[ 0 ]\n"; # Call Acorbat LoadFile Method $PDFControl->CallMethod("LoadFile", $file[ 0 ]); return 0; } #resize to fit user input sub resize { my ($self) = @_; my ($width, $height) = ($self->GetClientRect())[2..3]; $self->PDFControl->Resize($width+1, $height+1) if exists $self->{PDFControl}; } #Exit the application sub QuitFile { my $self = shift; #Set the Acrobat control to nothing $PDFControl->CallMethod("LoadFile", ""); #This line is needed to keep the PERL interperter from crashing $PDFControl->Release(); return -1; }