Wednesday, July 13, 2011

To Find the FieldName in PDF Template

1) Install the ABCPdf.net (Trial version is fine)
2) Create a VBScript file (vbs) with following code

----------------------Code Begin ---------------------------------
Set TxtFile = CreateObject("Scripting.FileSystemObject")
Set WriteStuff = TxtFile.OpenTextFile("FieldName.txt", 8, True)

Set theDoc = CreateObject("ABCpdf7.Doc")
theDoc.Read "myForm.pdf"
theDoc.AddFont "Arial"
theDoc.FontSize=16
theDoc.Rect.Pin=1

Dim theIDs, theList
theIDs = theDoc.GetInfo(theDoc.Root, "Field IDs")
theList = Split(theIDs, ",")

For Each id In theList
theDoc.Page = theDoc.GetInfo(id, "Page")
theDoc.Rect.String = theDoc.GetInfo(id, "Rect")
theDoc.Color.String = "240 240 255"
theDoc.FillRect()
theDoc.Rect.Height = 16
theDoc.Color.String = "220 0 0"
WriteStuff.WriteLine( id + " " + theDoc.GetInfo(id, "Name"))
theDoc.AddText(theDoc.GetInfo(id, "Name"))
theDoc.Delete(id)
Next

theDoc.Save "output.pdf"
theDoc.Clear

WriteStuff.Close
SET WriteStuff = NOTHING
SET TxtFile = NOTHING

MsgBox "Finished"

----------------------Code End -----------------------------------
2) Copy the PDF template file to the same folder where the vbs file is kept
3) You will get two output (1) A PDF (output.pdf) File with FieldName written in fields (2)A text file (FieldName.txt) with field name too.

No comments:

Post a Comment