Solved

How to control a temp file that continually increases.

Posted on 2004-08-30
5
254 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

680 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