Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to launch a pdf file from VB application?

Status
Not open for further replies.

jasontektips

Programmer
May 30, 2003
23
SG
Hi,

Is there a way to launch a pdf file in Acrobat Reader from a VB application? For example, I have a simple VB standalone application to search for a pool of pdf files, and upon clicking on one of the pdf files, VB will launch Acrobat Reader and the pdf file appears.

Would appreciate deeply if anyone can help or point to any reference for this.

Many thanks :)
Jason

 
Just Shell to it:

shell "myacrobatpath\acrord32.exe mypdf.pdf",vbNormalFocus

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
johnwm:
lets say the pdf file is in d:\ wont this work?
shell "d:\mypdf.pdf",vbNormalFocus

Known is handfull, Unknown is worldfull
 
vbkris,
Did you try that before posting? or is it a hunch?
AFAIK the Shell function runs an executable and (optionally) returns the program's task ID. If you want the program to open something, as in my example you need to pass this in exactly the same way as you would pass a command line parameter

You may be thinking of the ShellExecute API call, which takes a filename as one of it's parameters.

You need to declare the function in a module:

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Then in your form:

Dim X As Long
X = ShellExecute(Me.hwnd, "Open", FileName, 0&, 0&, 3)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
i have used shell before but that was for activatng a flash exe file. so i thought why not pdf?

[ponder]



Known is handfull, Unknown is worldfull
 
Hi,

Actually I'm trying out on a project with a simple search engine VB application that'll search in a fix pool of pdf files for some pdf files of interest, and upon clicking on the selected pdf file, the Acrobat reader application will launch with the pdf file. All these, that is the VB application, the pool of pdf files and the Acrobat Reader, must reside in a CD. And thus I can just bring the CD to any PC(running Windows I suppose) to run this application.

I dunno whether this is possible in the first place?

With my limited knowledge and experience in VB, I was thinking of hardcoding the pdf file names(abt 400 of them) into an array to facilitate the search. But my problem is how to make the resulting pdf file 'clickable' and thus make it launch in the Acrobat Reader(that is residing in the CD).

Appreciate any help in this, and if possible reference me to somewhere with any related sample codes :)
Many many thanks.

regards,
Jason

 
Sorry Jasontektips

I sort of assumed that you (as one of the forum's top experts) only needed a pointer.

Try this:
On a new form add a listbox control (List1)
[tt]
In the Form_Load event paste this:
Dim myDoc As String
myDoc = Dir("c:\program files\visio\docs\*.pdf")
List1.Clear
List1.AddItem myDoc
Do While myDoc <> &quot;&quot;
myDoc = Dir
List1.AddItem myDoc
Loop
[/tt]
In the List1_Click event paste this:
[tt]
Dim strProg As String
Dim strFile As String
strProg = &quot;c:\program files\adobe\acrobat 6.0\reader\acrord32.exe&quot;
strFile = &quot;c:\program files\visio\docs\&quot;
Shell (strProg & &quot; &quot; & strFile & List1.List(List1.ListIndex)), vbNormalFocus
[/tt]

You'll have to change the RED bits to point to the appropriate places on your computer of course

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Hi Jonhwm,

hey thanks :) I tried the codes and it works.
I manage to launch the Acrobat Reader from the CD too.
But one problem, I need user to select their CDROM drive (by using the Drive control) so as to get the full path of the acrord32.exe and the pdf file that is residing in the CD. Is there a way to automatically obtain user's CDROM drive from my VB application(that's also reside in the CD)?

Thanks.
jason
 
You could use the File System Object, but it's easier to use App.Path (which returns the path that your app is running from). If your app (in the Program directory) is running from a CD which is mapped as X: then App.Path will give &quot;X:\Program&quot;

You can get the root of the drive from Left$(App.Path,2)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top