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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with ACRODISTXLib for using Adobe Distiller in VB.NET

Status
Not open for further replies.

psychmail

Technical User
Oct 25, 2005
7
BE
Hello,

I'm building an application that converts PS-files to the PDF format using Distiller Automation. I've written a testprogram and everything works fine. ONCE! If I try to run the program again, it throws an exeption:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in DistillerAPI_Converter.exe

This is because when I fire up the program the first time, it creates a acrodist.exe process(the actual Adobe Distiller), but I don't seem to succeed in closing that process down. :-(

When I close my program, the acrodist process ends like it should, but the problem occurs when I have converted one, or several files, and try to do this again without restarting the program.

Below the code I use:
Code:
[COLOR=green]'Author:    Tim Wuytens
'Goal:      Convert *.ps to *.pdf using adobe acrobat distiller automation
'Date:      2005-10-25[/COLOR]
Imports System.IO
Imports ACRODISTXLib
Public Class frmDistillerAPI_Converter
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
[COLOR=green]'omitted code for form generation
'it's a simple form with a textbox, a listbox and 2 buttons(start and browse)[/color]
#End Region
    
[COLOR=green]'Declare object with its events[/color]
Public WithEvents objDistil As PdfDistiller6

[COLOR=green]'Handler for the Click event on the Browse button
'Shows a filedialog where you can select one or multiple files
'and puts these filenames in a listbox[/color]
Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnBrowse.Click
    Dim str As String
    With OpenFileDialog1
        .CheckFileExists = True
        .CheckPathExists = True
        .Multiselect = True
        If DialogResult.OK = .ShowDialog Then
            For Each str In .FileNames
                lstPad.Items.Add(str)
            Next
        End If
    End With
End Sub

[COLOR=green]'Handler for the Click event on the Start button[/color]
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnStart.Click
    Dim InputPS As String
    Dim str, OutputPDF, JobOptions As String
 
    [COLOR=green]'set reference to new object[/color]       
    objDistil = New PdfDistiller6

    [COLOR=green]'iterate through all listitems[/color]
    For Each str In lstPad.Items
        InputPS = str
        OutputPDF = InputPS.Substring(0, InputPS.LastIndexOf(Path.DirectorySeparatorChar))
        OutputPDF &= "\pdf\"
        If Not Directory.Exists(OutputPDF) Then
            Directory.CreateDirectory(OutputPDF)
        End If

        [COLOR=green]'catch result and show in textbox[/color]
        Dim res As Short
        [COLOR=green]'the FileToPDF function does the actual conversion
        'it works fine, even when multiple files are selected
        'however, when the button is clicked again
        'the exception mentioned above is thrown
        'I know for sure this is because the acrodist.exe process is still running
        'because I tried manually ending it between two clicks, and then
        'it works fine again[/color] 
        res = objDistil.FileToPDF(InputPS, OutputPDF, JobOptions)
        txtUit.AppendText(res)            
    Next
        
    [COLOR=green]'release the object reference
    '(was meant for ending the process acrodist.exe, but doesn't do its job)[/color]
    objDistil = Nothing
End Sub

[COLOR=green]'OnLogMessage catches the logmessages that normally would appeat in the distiller log[/color]
Private Sub objDistil_OnLogMessage(ByVal strMessage As String) Handles objDistil.OnLogMessage
    strMessage = strMessage.Replace(vbLf, vbNewLine)
    txtUit.AppendText(strMessage)
End Sub

End Class
Obviously I need to release the object one way or another, but I'm out of ideas here :-s

Any information would be greatly appreciated.

Thanx in advance.
 
You might try the vb.net column, as this column is really intended for VB6 users.

HTH

Bob
 
Oh I'm sorry.

I did post the tread in both colums. And also in the Adobe acrobat section.

And for those who care... the problem was solved rather easy by putting the line 'objDistil = new PdfDistiller6' in the form_load event instead in the Start button click event.

This causes the creation of distiller process at startup, but this object can be used several times without any errors. And the object is automatically released when the form closes down.

Thanks to Tgreer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top