Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hello
i am using windows xp with activeperl 5.10 , i want to call a windows dll such as AcroPDF.dll to display a pdf file within a win32 gui window?. i have seen a small code in VB6 titled: How to use Adobe Acrobat Reader 7.0 Viewer Control (AcroPDF.dll) in
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=69282&lngWId=1
wich can realy display a pdf file on the form of the visual basic 6 ,i hope there is no opposition to display the vb6 code here for the attention of who may infer something from it, there is a little docs about calling dll's from perl, and any ideas to call this AcroPDF.dll could help many people in calling another dll's
thank you very much
it is a small code but commented heavily
' Demonstrated by: Julius Enerio ' Requirements: Make sure the Adobe Acrobat 7.0 Control Type Library ( +AcroPDF.dll) is visible in your toolbox ' Right Click on the toolbox then select Components. Select Adobe Acro +bat 7.0 Control Type Library then click OK ' No need to add the control in the form though. Just use the code. ' Read More on how to use the browser control by reading the Interappl +ication communication API Reference found by searching in on Google Option Explicit 'Which means all variables must be declared before it +can be used in the program Private m_objPDF As AcroPDFLibCtl.AcroPDF 'Declare an object of type A +croPDF Private m_strFilePath As String 'Declare a string for the PDF Filename + and Path 'On Form Load... Private Sub Form_Load() m_strFilePath = App.Path & "\Quran_Page_013.pdf" 'Change this to th +e path and filename of your PDF File Set m_objPDF = Controls.Add("AcroPDF.PDF.1", "Test") 'This will add + the PDF Browser control to the form on runtime. The "Test" is the co +ntrol's name Set m_objPDF.Container = Frame1 'Attach the PDF Browser control to +a container. 'A Container can be a Frame, PictureBox, or SSTab Control. In this +code, I used a Frame. End Sub 'On Form Activate Private Sub Form_Activate() 'Load the PDF file specified in m_strFilePath. 'Make sure to do this before doing any changes to the browser contr +ols view/layout m_objPDF.LoadFile m_strFilePath 'Set whether a toolbar will appear in the viewer. True to show, Fal +se to Hide. m_objPDF.setShowToolbar False 'Sets the Layout Mode for a page view according to the specified st +ring. 'DontCare — use the current user preference 'SinglePage — use single page mode (as it would have appeared in pr +e-Acrobat 3.0 viewers) 'OneColumn — use one-column continuous mode 'TwoColumnLeft — use two-column continuous mode with the first page + on the left 'TwoColumnRight — use two-column continuous mode with the first pag +e on the right m_objPDF.setLayoutMode "SinglePage" 'Sets the page mode in which a document is to be opened 'PDDontCare: 0 — leave the view mode as it is 'PDUseNone: 1 — display without bookmarks or thumbnails 'PDUseThumbs: 2 — display using thumbnails 'PDUseBookmarks: 3 — display using bookmarks m_objPDF.setPageMode "none" 'Set the Zoom view according to the value specified. ranges from 0 +and onwards m_objPDF.setZoom 240 'Move and Resize the object in relation to its container/form With m_objPDF .Move 125, 175, 7800, 8415 'x-position, y-position, width, heigh +t End With 'Show the Browser Control m_objPDF.Visible = True End Sub 'On Form Unload Private Sub Form_Unload(Cancel As Integer) 'The Browser control will load a blank m_objPDF.LoadFile "" 'Set object to nothing Set m_objPDF = Nothing End Sub

Replies are listed 'Best First'.
Re: calling AcroPDF.dll from perl
by rpnoble419 (Pilgrim) on Jul 05, 2008 at 07:34 UTC
    Try this. It works with 5.8 and Win32::GUI. Keep in mind this is a sample application and you should refer to the Adobe Acrobat SDK for more information.
    #!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->{PDF +Control}; } #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; }
      thank you very much "rpnoble419" , your code have worked well on my machine.
      i have searched hard on the win32 gui forums and other forums with no success
      i am sure this is the first time someone have published a complete code to display a pdf file inside a win32 gui window
      hope many people will benefit from it
      best regards

      Very Thanks for provide Perl source code to Display PDF Files in Win32 GUI

Re: calling AcroPDF.dll from perl
by Anonymous Monk on Jul 05, 2008 at 00:53 UTC