Solved

How to control a temp file that continually increases.

Posted on 2004-08-30
5
250 Views
Last Modified: 2012-05-05
Hello,

We have a program that was built to convert about three million tiff files to pdf. Yet the

program hangs after about 6,000 to 7,000 conversions. Upon investigation we discovered the

AcroApp object (Acrobat Pro 6.0) created some temp files, one of which will grow in size as the

program runs. Eventually, when the temp file reaches the size of the system pagefile the program

hangs. As a work around we tried modifying the program to do the following upon the completion of

each folder. (See examples below.)

1. Destroy the Acrobat objects
2. Delete the temp files
3. recreate the Acrobat objects

Unfortunately this didn't work, inside the program we got a 'permission denied' error and when

trying to manually delete the file from Explorer we got a error stating 'the file is in use by

another program'. The only way we were able to delete the temp files was to stop the 'exe'.

Would anyone know of a way to deal with this problem without having to stop the 'exe' or increase

the pagefile size?

Thanks in advance,


Bill


---   Original Code   ---

Private Sub Convert_Tif_2_PDF()

    Dim TifRoot As String
    Dim PdfRoot As String
    Dim TifFile As String
    Dim PdfFile As String
   
    TifRoot = "D:/Registry/Tiff"
    PdfRoot = "D:/Registry/PDF"
   
   
    Dim File As File
    Dim Files As Files
    Dim Fldr As Folder
    Dim Fldrs As Folders
   
    Set Fldr = FSO.GetFolder(TifRoot)
    Set Fldrs = Fldr.SubFolders
    Set AcroApp = CreateObject("AcroExch.App")
    Set AVDoc = CreateObject("AcroExch.AVDoc")
   
    For Each Fldr In Fldrs
        Set Files = Fldr.Files
        CreateFldr (PdfRoot & "/" & Fldr.Name)
        For Each File In Files
            TifFile = FSO.BuildPath(Fldr.Path, File.Name)
            PdfFile = PdfRoot & "/" & Fldr.Name & "/" & FSO.GetBaseName(File.ShortName) & ".pdf"
            '
            Call AVDoc.Open(TifFile, "")
            Set AVDoc = AcroApp.GetActiveDoc
            If AVDoc.IsValid Then
                Set PDDoc = AVDoc.GetPDDoc
                If PDDoc.Save(1 Or 4 Or 32, PdfFile) <> True Then
                    i = 1 / 0 ' Force error
                End If
                PDDoc.Close
            End If
            AVDoc.Close True
        Next
    Next

    AcroApp.Exit
           
    'Cleanup
    Set PDDoc = Nothing
    Set AVDoc = Nothing
    Set AcroApp = Nothing
End Sub


---   Modified Code   ---

Private Sub Convert_Tif_2_PDF()

    Dim TifRoot As String
    Dim PdfRoot As String
    Dim TifFile As String
    Dim PdfFile As String
   
    TifRoot = "D:/Registry/Tiff"
    PdfRoot = "D:/Registry/PDF"
   
   
    Dim File As File
    Dim Files As Files
    Dim Fldr As Folder
    Dim Fldrs As Folders
   
    Set Fldr = FSO.GetFolder(TifRoot)
    Set Fldrs = Fldr.SubFolders
    Set AcroApp = CreateObject("AcroExch.App")
    Set AVDoc = CreateObject("AcroExch.AVDoc")
   
    For Each Fldr In Fldrs
        Set Files = Fldr.Files
        CreateFldr (PdfRoot & "/" & Fldr.Name)
        For Each File In Files
            TifFile = FSO.BuildPath(Fldr.Path, File.Name)
            PdfFile = PdfRoot & "/" & Fldr.Name & "/" & FSO.GetBaseName(File.ShortName) & ".pdf"
            '
            Call AVDoc.Open(TifFile, "")
            Set AVDoc = AcroApp.GetActiveDoc
            If AVDoc.IsValid Then
                Set PDDoc = AVDoc.GetPDDoc
                If PDDoc.Save(1 Or 4 Or 32, PdfFile) <> True Then
                    i = 1 / 0 ' Force error
                End If
                PDDoc.Close
            End If
            AVDoc.Close True
        Next
        ' This block of code attempts to destroy the Acrobat objects,
        ' delete the temp files and then recreate the objects.
        ' Unfortunately it doesn't work. On both of the delete statements,
        ' it gives an error stating the file is in use by another program.
        '
        AcroApp.Exit
        Set PDDoc = Nothing
        Set AVDoc = Nothing
        Set AcroApp = Nothing
        On Error Resume Next
        FSO.DeleteFile "C:\Documents and Settings\bill\Local Settings\Temp\*.tmp", True
        Kill "C:\Documents and Settings\bill\Local Settings\Temp\*.tmp"
    Next

    AcroApp.Exit
           
    'Cleanup
    Set PDDoc = Nothing
    Set AVDoc = Nothing
    Set AcroApp = Nothing
End Sub
0
Comment
Question by:Fleurys
5 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 200 total points
ID: 11939173
Try to terminate proces this way:

    Dim lngProcessID As Long
    Dim lngReturnValue As Long
    Dim lngProcess As Long
    lngReturnValue = GetWindowThreadProcessId(AcroApp.hwnd, lngProcessID)
    lngProcess = OpenProcess(PROCESS_ALL_ACCESS, 0&, lngProcessID)
    lngReturnValue = TerminateProcess(lngProcess, 0&)
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11939175
Also wait at least 5 seconds to the app to terminate.
0
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 11939574
Well I think the there's one more problem the application using the temp file will be running, if we force the temp file to close that application might malfunction???
0
 

Author Comment

by:Fleurys
ID: 11939902
Hi Jamie,

That was a nice idea but the AcroApp Object doesn't have a handle property.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 11940219
Personally, I'd do some more research and try to discover why the files can't be destroyed.  Failing that I believe I'd contact Adobe.  The only other thought that comes to mind is to either run the conversions in another thread, which would require converting the program to multi-threading, or divide the program into two programs.  The first program would be a main routine that spawns the second program, the conversion routine.  The main program would enumerate the folders and spawn the conversion program once for each folder.  It'd pass the  name of the folder to process to the second exe which would convert all the files it finds there, and then exit.  Since the offending Acrobat objects would only be in the second program, they'd be disposed of each time it closed.  That'd keep them from being a problem.  The downside is that this approach would be slower.  The multi-threading approach would be faster, you could have several threads converting files simultaneously.  But it is more complicated and might involve the purchase of additional products.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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

20 Experts available now in Live!

Get 1:1 Help Now