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:
    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")
    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
    '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, stempFile) = False Then
        MsgBox "Unable to save image"
    End If
    AVDoc.Close True

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

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

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?

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

dim Wshshell
dim retcode
dim sInFile
DIM sInputPath
DIM oFile
DIM oFolder
DIM oFiles


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 = (sInfile, 1, TRUE)

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.