WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Acrobat Viewer

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Deal with Fields on a PDF form


;Winbatch
;create get/put subroutines for fields on PDF form
;
;Stan Littlefield - please retain this header
;/////////////////////////////////////////////////////////////////
cPDF = AskFilename("Select PDF with Form Fields", DirScript(), "PDF Files|*.pdf", "", 1)
If ! FileExist(cPDF) Then Exit

BoxOpen("Please Be Patient...","Enumerating Fields in %cPDF%")

AcroApp = CreateObject("AcroExch.App")
AvDoc = CreateObject("AcroExch.AVDoc")
PDDoc = CreateObject("AcroExch.PDDoc")
cUDF=""

If AvDoc.Open(cPDF,"") Then
   AcroApp.Show()
   AvDoc = AcroApp.GetActiveDoc()
   Goto getput
Else
   Display(2,"Unable to open the PDF-file", "Program Terminating")
   Goto End
EndIf

:close
Display(3,"%cUDF% Created","%cPDF% Closing in 3 Seconds")
AvDoc.Close(@TRUE)
AcroApp.CloseAllDocs()
AcroApp.Exit()

:End
BoxShut()
AvDoc = 0
PDDoc = 0
AcroApp = 0
Exit

:CANCEL
Exit

:getput
cUdf = StrReplace( StrUpper(cPDF),".PDF","_UDS.wbt")
If FileExist(cUdf) Then FileDelete(cUdf)
cStart=""
cStart = StrCat(cStart,"#DefineSubroutine getform(mode)",@CRLF)
cStart = StrCat(cStart,'AcroForm = CreateObject("AFormAut.App")',@CRLF,"Fields = AcroForm.Fields",@CRLF)
cStart = StrCat(cStart,'If mode Then getfields()',@CRLF,'Else',@CRLF,"putfields()",@CRLF,"Endif",@CRLF)
cStart = StrCat(cStart,"Return(1)",@CRLF,"#EndSubRoutine",@CRLF,@CRLF)
cStart = StrCat(cStart,'AcroApp = CreateObject("AcroExch.App")',@CRLF)
cStart = StrCat(cStart,'AvDoc = CreateObject("AcroExch.AVDoc")',@CRLF)
cStart = StrCat(cStart,'PDDoc = CreateObject("AcroExch.PDDoc")',@CRLF)

cTxt = StrCat("#DefineSubroutine getfields()",@CRLF)
cTxt1 = StrCat("#DefineSubroutine putfields()",@CRLF)

AcroForm = CreateObject("AFormAut.App")
Fields = AcroForm.Fields

ForEach f In Fields
   cTxt = StrCat(cTxt,"v_",f.name,'= Fields.Item("',f.name,'").Value ;fieldtype:',f.type,@CRLF)
   cTxt1 = StrCat(cTxt1,'Fields.Item("',f.name,'").Value= "[value]"',@CRLF)
Next
cTxt = StrCat(cTxt,"Return(1)",@CRLF,"#EndSubRoutine",@CRLF,@CRLF)
cTxt1 = StrCat(cTxt1,"Return(1)",@CRLF,"#EndSubRoutine",@CRLF,@CRLF)
FilePut(cUDF,StrCat(cTxt,cTxt1,cStart) )
AcroForm = 0
Goto close


Article ID:   W17143
File Created: 2007:07:03:14:28:28
Last Updated: 2007:07:03:14:28:28