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

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
RenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tdyck12345Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RenAuthor Commented:
 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
tdyck12345Commented:
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
Tyger McClureFinancial Systems ManagerCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.