Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 25th, 2005, 09:13 AM
psych psych is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Location: Lommel, Belgium
Posts: 2 psych User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m
Reputation Power: 0
Exclamation Distiller problem in VB.NET

Hi everyone,

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:
'Author:    Tim Wuytens
'Goal:      Convert *.ps to *.pdf using adobe acrobat distiller automation
'Date:      2005-10-25
Imports System.IO
Imports ACRODISTXLib
Public Class frmDistillerAPI_Converter
    Inherits System.Windows.Forms.Form

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

'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
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

'Handler for the Click event on the Start button
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
 
    'set reference to new object       
    objDistil = New PdfDistiller6

    'iterate through all listitems
    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

        'catch result and show in textbox
        Dim res As Short
        '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
        res = objDistil.FileToPDF(InputPS, OutputPDF, JobOptions)
        txtUit.AppendText(res)            
    Next
        
    'release the object reference
    '(was meant for ending the process acrodist.exe, but doesn't do its job)
    objDistil = Nothing
End Sub

'OnLogMessage catches the logmessages that normally would appeat in the distiller log
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

Any information would be greatly appreciated.

Thanx in advance.

Reply With Quote
  #2  
Old October 28th, 2005, 11:20 PM
asc11 asc11 is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: May 2005
Posts: 894 asc11 User rank is Sergeant Major (2000 - 5000 Reputation Level)asc11 User rank is Sergeant Major (2000 - 5000 Reputation Level)asc11 User rank is Sergeant Major (2000 - 5000 Reputation Level)asc11 User rank is Sergeant Major (2000 - 5000 Reputation Level)asc11 User rank is Sergeant Major (2000 - 5000 Reputation Level)asc11 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 5 h 23 m 4 sec
Reputation Power: 37
Setting an Object Variable to Nothing only releases the reference to the Object in memory. Depending on the Object, it does not necessarily release the resources. I have noticed this problem espcially in .NET. You need to actually Destroy or Dispose of the Object, not just release the reference.

If the PdfDistiller6 class doesn't come with its own destructor, then you may have to put the actuall Object in a seperate class and include your own Constructor/Destructor methods. Check MSDN for more details. Basically, this way, you put the Distiller Object into a custom Class and then create a reference to the Class in your Form module. When you need to release the Distiller, you call the custom destructor of the Class it is in. Then you can reinitalize the Class Object to create another Distiller Object.

Let us know if you need more help/details.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Distiller problem in VB.NET


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT