Data Mailer
Now we have to write the MakeSubsDictionary() function we used earlier. Here it is:
defMakeSubsDictionary(data):dictSubs={'/N':data[0],'/F1':data[1],'/F2':data[2],'/F3':data[3],'/F4':data[4],'/F5':data[5],'/F6':data[6]}returndictSubs
This creates a dictionary where the keys are all the strings that will be replaced in the template, and the elements are the data that will replace them.
So now, let's put it all together:
importacrobat# FORMAT:# NAME, FEATURE1, FEATURE2, FEATURE3, FEATURE4,# FEATURE5, FEATURE6, PICTUREFILEdata=(('Jeffrey','3 Bedrooms','2 Bathrooms','A Swimming Pool','','','','house1.pdf'),('Gary','5 Large Bedrooms','3 Bathrooms','3-Car Garage',"Lot's of Shady Trees",'Satelite Dish','Hot Tub','house2.pdf'))defMakeSubsDictionary(data):dictSubs={'/N':data[0],'/F1':data[1],'/F2':data[2],'/F3':data[3],'/F4':data[4],'/F5':data[5],'/F6':data[6]}returndictSubsdefDataMailer(sTemplateFile,tupData):doc=acrobat.documentOpen(sTemplateFile)docNew=acrobat.documentNew()docNew[:]=doc[0:1]*len(tupData)foriinrange(len(tupData)):dictSubs=MakeSubsDictionary(tupData[i])docNew[i].textrunReplace(dictSubs)returndocNew doc=DataMailer(r'd:\pdfer\wwwroot\tutorial\template.pdf',data)doc.forceVisible()
As before, you'll have to change the path of template.pdf to where ever it is on your computer.
So copy this chunk into your text editor, save it to DataMailer3.py and then open it using Acrobat. You should get a result like this.