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!

Distiller automation VB.NET 1

Status
Not open for further replies.

psychmail

Technical User
Oct 25, 2005
7
BE
Hi there,

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.
 
Distiller isn't licensed for servers. Adobe does provide various Automation objects for their products, but they are poorly documented and terribly buggy. I wouldn't base any solution around any type of Acrobat and/or Distiller automation.

I recommend activePDF Server for COM-based, multi-threaded, server-based PostScript-to-PDF conversion.

Barring that, try Distiller Watched Folders instead of automation.



Thomas D. Greer
 
Thanks for your reply tgreer!

However I don't see what this has to do with servers. I only select local files.

I'll look at the activePDF you're talking about, but the people I'm making the project for prefer the use of Adobe Distiller.

Also, there now runs a simple script which uses the 'watched folder' capabilities of Distiller. This is not fail-safe and therefore I'm trying to create this program.

What I wonder is why the acrodist.exe process DOES end when I close the application, without any specially written closing routines for the program; but DOES NOT end when I try to release the object trough code.

tnx
 
I don't know, and you won't find any helpful pointers in Adobe's documentation. The Distiller Automation object only has 3 methods, and "close" or "quit" isn't one of them. The documentation never explicitly mentions closing/killing the object.

Therefore, I would try a couple of things:

1) Create your Distiller object during the load event. That way it instantiates once for the entire scope of the application, rather than inside a click event. Use the same Distiller instance throughout the application.

2) Use Distiller's command-line options rather than Automation; run Distiller via Process.Start rather than Automation.



Thomas D. Greer
 
The Distiller Automation object only has 3 methods, and "close" or "quit" isn't one of them. The documentation never explicitly mentions closing/killing the object.
I've noticed that yes. The more I get to know about the Distiller and the amount of information available, the less I appreciate Adobe.
Who creates interfaces and COM objects without the ability to close them?! Go figure!

Anyway thanks a lot. Simply putting the line
objDistil = New PdfDistiller6
in the Form_Load event did the trick. It's a little less memory friendly,(cause the acrodist process is started with the program, even if you don't convert anything) but it works like a charm.

Thanks a lot

Tim Wuytens
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top