Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Document To PDF Kill acrodist Service


Message #1 by "Henry" <henrywolfe@y...> on Mon, 16 Dec 2002 14:52:01
When I try to convert a document to a PDF using vb.net the first step it 
does is convert the document into a postscript file from here it opens up 
the adobe distiller and converts it to a PDF.  It works with no problems 
the first time around but what happens is the acrodist.exe service stays 
open so when I run the code a second time I get a

An unhandled exception of 
type 'System.Runtime.InteropServices.COMException' error.  

I want to be able to check to see if this acrodist.exe service is running 
and if it is kill it.  How would I do that?

Thanks

Henry Wolfe

Here is my code.



   Function ConvertToPDF(ByVal sSourceDocPath, ByVal sSavePsPath, ByVal 
sSavePDFPath) As String
            'This section creates the PostScript File from a msword 
document
            Dim wrdApp As New Word.Application()
            Dim wrdDoc As Word.Document

            Try
                'Open the word Document 

                wrdDoc = wrdApp.Documents.Open(sSourceDocPath)
                wrdDoc.Application.DisplayAlerts = 
Word.WdAlertLevel.wdAlertsNone
                'Set the printer where the word document should be 
printed do not set this printer as system default
                'wrdApp.ActivePrinter = ("Acrobat Distiller")
                wrdApp.WordBasic.fileprintsetup(Printer:="Acrobat 
Distiller on NE22:", _
                DoNotSetAsSysDefault:=1)

                wrdApp.Options.PrintBackground = False


                wrdDoc.PrintOut(False, False, , sSavePsPath)


                'Close word
                CType(wrdApp, Word._Application).Quit(SaveChanges:=False)
                wrdDoc = Nothing
                wrdApp = Nothing

            Catch
                If TypeName(wrdApp) = "ApplicationClass" Then
                    CType(wrdApp, Word._Application).Quit
(SaveChanges:=False)
                    wrdDoc = Nothing
                    wrdApp = Nothing
                End If


                Return "Failed"
            End Try

            'This sections calles the Adobe Distiller and converts the 
PostScript File into PDF


            Dim oDist As New ACRODISTXLib.PdfDistiller()


            Try
                oDist.bShowWindow = False
                oDist.bShowWindow = 0
                oDist.FileToPDF(sSavePsPath, sSavePDFPath, "")
                oDist = Nothing
                Kill(sSavePsPath)
                Return "Success"
            Catch
                oDist = Nothing
                Return "Failed"
            End Try

        End Function

  Return to Index