Topic Options
#16996 - 01/09/06 03:28 PM Using CreateObject("AFormAut.App") in external program
John Dalzell Offline
Junior Member

Registered: 01/08/04
Posts: 25
Hi, I have written an external program in VB that instantates adobe Acrobat loads a pdf file and inserts data within fields defined in the PDF file using the adobe SDK. The app works fine when testing outside the PW environment. But when I test within the PW environment I get a Microsoft Visual C++ runtime error then a "Unable to create object" error from the VB app. The only way it will work within PW is if I already have a adobe acrobat instance running on the PC.

PC is Windows/2000 SP4
PW is Version 4

The VB code fragment follows:
Code:
  
    Dim formApp     As AFORMAUTLib.AFormApp
    Dim acroForm    As AFORMAUTLib.fields
    Dim field       As AFORMAUTLib.field
    Dim myField     As AFORMAUTLib.field
    
    Dim AcrApp      As acrobat.CAcroApp

    Dim AVDoc       As acrobat.CAcroAVDoc
    Dim PDDoc       As acrobat.CAcroPDDoc
    
    Dim bOK         As Boolean
    
    stempFile = mWorkPath & "temp.pdf"
    
    If SFS.FileExists(sOutFile) Then SFS.DeleteFile (sOutFile)
    If SFS.FileExists(stempFile) Then SFS.DeleteFile (stempFile)

    SFS.COpyFile mPosterLibrary & SR(idx).POSTERFILE, stempFile

    Set AcrApp = CreateObject("AcroExch.App", "localhost")
    DoEvents
    Set AVDoc = CreateObject("AcroExch.AVDoc", "localhost")

    bOK = AVDoc.Open(stempFile, stempFile)
    Set formApp = CreateObject("AFormAut.App", "localhost")
    Set acroForm = formApp.fields
    
    For index2 = 1 To UBound(SR(idx).field())
        For Each myField In acroForm
            If myField.Type = "text" Then
                If myField.Name = SR(idx).field(index2) Then
                    myField.Value = SR(idx).FIELDVALUE(index2)
                    Exit For
                End If
            End If
        Next
    Next
    
    'This section converts a AVDoc to a PDDoc. Then we use PDDoc.Save to
    'save the PDF since there isn't a viewer level method to save an AVDoc.
    
    Set PDDoc = AVDoc.GetPDDoc

    If PDDoc.save(PDSaveFull, stempFile) = False Then
        MsgBox "Unable to save image"
    End If
       
    AVDoc.Close True
    AcrApp.CloseAllDocs
    AcrApp.Exit

    Set PDDoc = Nothing
    Set AVDoc = Nothing
    Set acroapp = Nothing
    Set formApp = Nothing
    Set acroForm = Nothing

Top
#16997 - 01/12/06 08:08 PM Re: Using CreateObject("AFormAut.App") in external program
Anonymous
Unregistered


When you mention it does not work in the PlanetPress watch environment, are you running in debug mode with Planetpress Watch configuration or running it normally?

Top
#16998 - 01/12/06 08:26 PM Re: Using CreateObject("AFormAut.App") in external program
John Dalzell Offline
Junior Member

Registered: 01/08/04
Posts: 25
I am running normally. I actually worked around the problem by coding this in a planet press script:

Code:
dim Wshshell
dim retcode
dim sInFile
DIM sInputPath
DIM SFS
DIM oFile
DIM oFolder
DIM oFiles

sInputPath = "C:\PPWATCH_WC_POSTERS\INPUT\"

set Wshshell = CreateObject("WScript.Shell")
Set SFS = CreateObject("Scripting.FileSystemObject")
Set oFolder = SFS.getfolder(sInputPath)
Set oFiles = oFolder.Files

For Each oFile In oFiles
    sInFile = "C:\PPWATCH_WC_POSTERS\PGM\WC_WALL_POSTERS.exe " & sInputPath & oFile.Name
    retcode = Wshshell.run (sInfile, 1, TRUE)
next

set wshshell = nothing
Set oFile = Nothing
Set oFiles = Nothing
Set oFolder = Nothing
Set SFS = Nothing
The pgm WC_WALL_POSTERS.EXE executes the code fragment I listed in my initial post.

This seems to do the job, but still don't know why configuring a PW action to execute the program I am shelling out to above doesn't work.

Top