Parse through a FDF file.

Discussion, questions and support.
Post Reply
Marty123
Posts: 25
Joined: Apr 17th, ’22, 23:05

Post by Marty123 » Jun 25th, ’22, 15:25

Hi guys, need some help here with parsing through a FDF file, which is essentially a txt file that contains fields information of a pdf file which I will use later (the fdf file) to populate fields of the target pdf file.

The quick summary is that it is a plain text file consisting of key-value pairs. It is easy to parse and modify for someone who knows what he is doing, but i have no idea of how to do it. However, I'm intrigued by the idea of using excel file data to fill up this text file, which in turn becomes the backbone for filling up the actual pdf file using pdftk.exe (a program for manipulating pdf) 'fill_form' feature. Because each key is preceded by /T and each value by /V, i feel it is sort of easy for someone who is used to writing script for parsing, (not me though) to populate values. For example, here are a few lines from an FDF file:

/T (FirstName)
/V ()
/T (LastName)
/V ()
/T (Phone)
/V ()

basically I have no idea of how to start parsing thru mountain of text from a field heavy fdf file that is produced from a 30 page pdf file, to have my variables (like %firstname%) passed down to populate precisely in between the "()"

Hopefully u guys can give me some pointers or idea on where to start looking.

Thanks in adv.
User avatar
Marko
Posts: 1718
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jun 28th, ’22, 19:40

Here is one idea:

Code: Select all

string:="
(
/T (FirstName)
/V ()
/T (LastName)
/V ()
/T (Phone)
/V ()
)"
FirstName:="Marty"
StringReplace, string, string, /T (FirstName)`n/V (), /T (FirstName)`n/V (%FirstName%)
msgbox % string
Marty123
Posts: 25
Joined: Apr 17th, ’22, 23:05

Post by Marty123 » Jun 29th, ’22, 05:57

I will try it! Thanks Marko !
Post Reply