Solved

Close Acrobat Distiller from VB.NET after distilling a .prn

Posted on 2004-10-21
764 Views
Last Modified: 2016-06-06
Hi Experts,

I don't think this is a terribly difficult question, I just need someone to tell me how to do it.  I've been working on this all morning and can't afford to waste anymore time on it.

My problem is simple:  I create a .prn file from an excel worksheet, then call the sub that sends the .prn to the distiller and move on to the next excel worksheet and do the same.  Problem is, when I get to the second .prn file for distilling, I get an error because the distiller is still open.  I know this is the problem because I can even put a stop statement in there and manually close the distiller each time to make it work.  HOW DO i GET THE DISTILLER TO CLOSE????  From what I've researched, it seems that the assignment of the object = Nothing and the GC.collect should do it, but it does not.
A rough example of my existing code below does not do that job.

'globalFileArray(global_CTR) = full path of .prn file

Sub A()
  For global_CTR = 1 to 10
    If globalFileArray(global_CTR) <> nothing then
      Call CreatePDF    '<-- Calls the PDF creation sub
    End If
  Next
End Sub

Sub CreatePDF()
  Try
    Dim objDis As New ACRODISTXLib.PdfDistiller
    objDis.FileToPDF(globalFileArray(global_CTR), "c:\abc.pdf", "")   <-- Errs on 2nd attempt b/c distiller is still open
    objDis = Nothing
  Catch X as Exception
    msgbox(err.description)    '<-- Gives me "The server threw an exception"
  End Try

  GC.Collect()
End Sub

Thanks Experts!
-Ren
0
Question by:Ren
    4 Comments
     
    LVL 2

    Accepted Solution

    by:
    It seems strange that the application does not close down. However, you can force the process to shut down:

    Sub CreatePDF()
      Try
         ' make sure Adobe Acrobat Distiller is closed
         Dim prc() As Process
         prc = System.Diagnostics.Process.GetProcessesByName("acrodist")
         Dim eprc As IEnumerator = prc.GetEnumerator
         eprc.Reset()

         While eprc.MoveNext
             Dim proc As Process = CType(eprc.Current, Process)
             proc.Kill()
             proc = Nothing
         End While

         eprc = Nothing
         prc = Nothing

        Dim objDis As New ACRODISTXLib.PdfDistiller
        objDis.FileToPDF(globalFileArray(global_CTR), "c:\abc.pdf", "")   <-- Errs on 2nd attempt b/c distiller is still open
        objDis = Nothing
      Catch X as Exception
        msgbox(err.description)    '<-- Gives me "The server threw an exception"
      End Try

      GC.Collect()
    End Sub

    Troy
    0
     

    Author Comment

    by:Ren
     I thought it was strange, too.  Am I correct in thinking the assignment of the object = Nothing coupled with the GC.Collect should close that?   Could it have something to do with calling the the sub from another sub?  Maybe that will make sense with a little more experience.

    Regardless, you nailed it!  All I had to do was cut and paste, thanks a million!

    -Ren
    0
     
    LVL 2

    Expert Comment

    by:tdyck12345
    You're welcome.

    Setting the object = nothing would not have done anything in this case because the pdfdistiller was spawning a new process that was independent of your object. Setting the object to nothing freed up the memory you had in your application but did not destroy the spawned process.

    The real problem is that adobe has a bug in their software.

    Troy
    0
     

    Expert Comment

    by:eltigrito
    Hello everyone,

    I'm having this same problem on a VM running a process that uses distiller to produce a PDF.
    Distiller remains open - and each night when the process runs, a new distiller window opens. The application running the process continues to think that the process hasn't completed - until Distiller is closed manually.

    Is there a BAT file command I can run to close distiller? I just need distiller to close via a scheduled task that I'll run 10 minutes after the task that creates the PDF.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: Foundations of Front-End Development

    Jump-start a lucrative career in front-end web development, with zero previous coding experience required. This course covers the basic programming concepts and languages required for creating engaging websites from scratch.

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

    845 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now