Open and close a PDF document

bruno

New member
Joined
Sep 27, 2005
Messages
1
Programming Experience
Beginner
Hi!!

i'm opening a pdf document using vb.net. I'm using this simple code:

Public Class PdfAutomation
Public WithEvents wxProcess As New Process

Public Sub OpenPdfVisible(ByVal sPath As String)
Try
wxProcess.StartInfo.FileName = sPath
wxProcess.Start()
wxProcess.EnableRaisingEvents = True
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Sub ClosePdf()
Try
wxProcess.Kill()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class

The problem is when i want to close the document. If i have more than one pdf document open they will close all the documents. The pdf .exe only creates one process to open all the documents.
I use this code to open and to close word documents:

Public Class Bookmarks

Dim Wapp As Object
Dim WFile As String
Dim wNewFile As String
Dim wBMP As String

WithEvents StopTimer As New Timers.Timer
Dim ResetFunction As Boolean

Dim LastOpenProcId As Int16
Public WithEvents myWordProcess As Process

Public Sub New()
End Sub

Function OpenApp(ByVal WordVisible As Boolean)
Try
if Wapp Is Nothing = True Then

Dim WordProcesses() As Process = Process.GetProcessesByName("Winword")

Dim pId() As Integer
ReDim pId(WordProcesses.Length)
Dim i As Int16
While i < WordProcesses.Length
pId(i) = WordProcesses(i).Id
i += 1
End While

Wapp = CreateObject("word.Application")
Wapp.Visible = WordVisible
WordProcesses = Process.GetProcessesByName("Winword")

Dim j As Int16
Dim bool As Boolean
For j = 0 To WordProcesses.Length - 1
Dim k As Int16
bool = False

For k = 0 To pId.Length - 1
If WordProcesses(j).Id = pId(k) Then
bool = True
Exit For
End If
Next
If bool = False Then
LastOpenProcId = WordProcesses(j).Id
myWordProcess = Process.GetProcessById(LastOpenProcId)
Exit For
End If
Next
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function

Function CloseApp(Optional ByVal WaitForExit As Integer = 20000)
Try
If WApp Is Nothing = False Then

ResetFunction = False
If WaitForExit <= 0 Then WaitForExit = 20000
StopTimer.Interval = WaitForExit
StopTimer.Start()

While WApp.BackgroundPrintingStatus = 1 Or WApp.BackgroundSavingStatus = 1
If ResetFunction = True Then Exit While : StopTimer.Stop()
End While

WApp.Quit()
WApp = Nothing

myWordProcess.WaitForExit(5000)

If Me.Exists = True Then
myWordProcess.Kill()
End If

End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function

I tryed to create an object like :pdfapp = CreateObject("pdf.Application") but it's not possible. I received a message:"Cannot create ActiveX component"...
Anyone can help me? Its' urgent.
 
Back
Top