Hi,
How can I show a PDF from vb.net form?
Printable View
Hi,
How can I show a PDF from vb.net form?
This form of code assumes that there is the standard file association between Adobe Acrobat and .pdf file extensions and will fire up Acrobat and show the named file.Code:Process.Start("H:\Jetway Manual.pdf")
if you have the full version of adobe acrobat installed, then you will be able to use the PDF ActiveX control that comes with it.
Not quite true, if you have Acrobat Reader you can use the pdf.ocx to display a pdf on a form, etc. depending onQuote:
Originally Posted by tr333
how much control you want over it you may still have to use the full version though.
Hi,
Thanks for your response. i did the following and it works.
VB Code:
Dim pdfProcess As Process pdfProcess = pdfProcess.Start("AcroRd32.exe", "c:\temp\a.pdf")
I've one more doubt. I hope the exe names for Acrobat will change like 'AcroRd32.exe' , 'Acro32.exe' etc., for different windows version. So how can I know the name of Acrobat's exe file in client' machine? :confused:
Or straightly can i give
pdfProcess= pdfProcess.Start("c:\temp\a.pdf")
to open the pdf straightly.
If there is no acrobat reader in clinet's machine , how can i track it???
Regards,
Hems.
Here is a way to get the associated program with the .pdf extension. Note, if the users system has another
program instead of Acrobat to open .pdf files then it will get that program and not Arobat.
VB Code:
Option Explicit On Imports System.IO Public Module Module1 Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, _ ByVal lpDirectory As String, ByVal lpResult As String) As Integer Public Sub FindAcrobat(ByVal strRunMe As String) Try 'CREATE SOME VARIABLES Dim PDFExec As String = New String(" "c, 255) Dim strFileName As String Dim lRet As Long Dim SWriter As StreamWriter 'CREATE A TEMP PDF FILE SO WE CAN FIND OUT WHERE THE LOCATION IS ONE ON THE SYSTEM strFileName = Application.StartupPath & "\temp.pdf" SWriter = File.CreateText(strFileName) SWriter.Write("1") SWriter.Close() 'CALL THE API TO FIND THE EXE ASSOCIATED WITH MOV FILES lRet = FindExecutable(strFileName, vbNullString, PDFExec) PDFExec = PDFExec.Trim 'IF WE GET ONE, LAUNCH THE PDF IN A NEW INSTANCE OF ACROBAT If lRet <= 32 Or PDFExec = String.Empty Then MessageBox.Show("Could not find Acrobat") Else Process.Start(PDFExec, strRunMe) End If 'DELETE THAT PESKY TEMP FILE File.Delete(strFileName) Catch ex As Exception 'IF ANYTHING GOES WRONG, LET PEOPLE KNOW WHO'S FAULT IT IS MessageBox.Show("An error has occured!" & ControlChars.CrLf & ex.Message) End Try End Sub End Module
Thanks RobDog !!
Sure, this is helpful for me !!! :wave:
I hope so, but I just modified a class klienma gave me to work for IE and made it work for Acrobat.
So, I can only take partial credit. ;)