Search English (United States)  Italiano (Italia) Deutsch (Deutschland)  Español (España, Alfabetización Internacional) Čeština (Česko)
Thursday, March 28, 2024 ..:: Articles » VB 6.0 » PDF in VBForm with no OCX/DLL (late binding) ::.. Register  Login
 Download Minimize

  
 Early-Late binding with Acrobat Reader Minimize

Sample projects for both VB 6.0 and VB.NET 2013

 


English version

Italiano

Continua la fortunata serie di di progetti relativi all'Early-late binding.
Fino ad ora abbiamo visto come applicare questa tecnica con Excel e Word (in VB.NET/C#), e con Excel e Outlook (in VB6.0).

Stavolta vedremo come usare questa tecnica per visualizzare i file PDF nelle nostre applicazioni.

Una volta era abbastanza semplice. Era sufficiente usare la libreria distribuita con Adobe Reader, AcroPDF.DLL:
- nel progetto si aggiungeva il riferimento a AcroPDF.DLL
- si aggiungeva il controllo sul form
- si caricava il file PDF usando il metodo LoadFile <filename>

Anche se questo metodo funziona bene, comunque molti sviluppatori continuavano ad avere problemi perchè bastava un cambio di versione di Acrobat Reader ed era tutto da rifare.

Proprio qualche giorno fa, Adobe ha aggiornato questa libreria che ora è a 64bit, così tutti gli sviluppatori che usavano la AcroPDF.DLL si sono visti fioccare telefonate dai loro clienti arrabbiati perché non riuscivano più a visualizzare i file PDF nelle applicazioni.
In poche ore il forum di Adobe è stato preso d'assalto da sviluppatori di ogni ambiente di sviluppo (C++, Delphi, .NET, VB6, ...) che chi più pacatamente, chi più arrabbiato si è lamentato che una modifica di tale portata avrebbe dovuto quanto meno essere preavvisata, per dar modo agli sviluppatori di porre rimedio prima di sentirsi tempestare di telefonate.

Bene, il metodo che illustrerò oggi non soffre di questi problemi perché lavora in 'late binding' senza necessità di usare alcun componente OCX o DLL.
Se lo implementate nelle vostre applicazioni, già domani potete distribuire la nuovo versione perché serve solo il file eseguibile, dato che non c'è nulla da installare.

Nel progetto viene infatti utilizzato un controllo di classe VBControlExtender, che rende possibile la creazione di un controllo di tipo WebBrowser (ieframe.dll) a run-time che viene dichiarato così:

Private WithEvents m_WebControl As VBControlExtender

poi nell'evento Load del form viene creata l'istanza:

Set m_WebControl = Controls.Add("Shell.Explorer", "WebControl", Me)

Come si può notare, ho utilizzato il ProgID "Shell.Explorer" al posto di "Shell.Explorer.2" perchè questo rende il controllo indipendente dalla versione, come indicato nel registro di Windows nella chiave VersionIndependentProgID in HKEY_CLASSES_ROOT\CLSID\{8856F961-340A-11D0-A96B-00C04FD705A2}.

 

Il progetto mostra come visualizzare i file PDF in un Form ma anche come caricarlo in un PictureBox.

 

 


English 

I continue the successful and well-attended series of projects relating to the Early-Late binding.

So far we have seen how to apply this technique with Excel and Word ( in VB.NET ), and Excel, and Outlook (VB 6.0).

This time we will see how to apply this technique to the display of PDF files in our applications.

Once it was simple. It was enough to use the library AcroPDF.dll, that come with Acrobat Reader:
- Adds to project a reference to the library AcroPDF.dll (which contains a control )
- You add the control to the form
- You upload the file with the LoadFile method <filename>

But many developers still struggle with the problem of versioning, which means that if the customer's computer has installed a different version of Acrobat Reader (AcroPDF.dll), the program no longer works.
Just a few days ago, Adobe has now updated this library is 64bit, so all developers who used AcroPDF.dll were seen flocking to their phone calls from angry customers because they could no longer view PDF files in your applications.
In a few hours the Adobe forum has been overrun by developers of each development environment (C + +, Delphi,. NET, VB6, ...) that those who more quietly, some more angry complained that an amendment to this flow should at least be given prior notice, in order to enable developers to remedy before you feel bombard calls.

Well, today I will illustrate the method does not suffer from these problems because it works in 'late binding' without the need to use any DLL or OCX component.
If implemented immediately in your applications, you can already tomorrow distribute the new executable because it serves only that, since there is nothing to install.

Well, today I will illustrate the method does not suffer from these problems because it works in 'late binding' without the need to use any DLL or OCX component.
If you implement it in your applications, tomorrow you may distribute the new version because need only the executable file, since there is nothing to install.

In the project is used a VBControlExtender class control, which makes it possible to create a control of type WebBrowser (ieframe.dll) at run-time which is declared as follows:

Private WithEvents m_WebControl As VBControlExtender

then, on form Load event we create the instance:

Set m_WebControl = Controls.Add("Shell.Explorer", "WebControl", Me)

As you can see, I used the ProgID "Shell.Explorer" instead of "Shell.Explorer.2" because this makes the control version-independent, as shown in the Windows registry key VersionIndependentProgID in the HKEY_CLASSES_ROOT\CLSID\{8856F961-340A-11D0-A96B-00C04FD705A2}.

 

The project shows how to display the PDF file in a Form and in a PictureBox, also.

 



  
Copyright (c) 2002-2021 Giorgio Brausi (aka gibra)   Terms Of Use  Privacy Statement
DotNetNuke® is copyright 2002-2024 by DotNetNuke Corporation