Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-21
4
Medium Priority
?
801 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
Comment
Question by:Ren
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
tdyck12345 earned 1200 total points
ID: 12374971
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
ID: 12380539
 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
ID: 12381643
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:Tyger McClure
ID: 41639340
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

610 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