Data Mailer
Fortunately, there is a lot of very useful Python code in the installed PDF Snake scripts that we can access very easily. In particular, in the Nup.py script, there is a function called FitSlot() which will put a page of any size into a rectangle of any size, and optionally preserve the aspect ratio. So, all we need to do is import Nup and call the FitSlot() function to put the picture of the house exactly where we want it. Here's the result, and here's the code:
importacrobatimportsysimportos.pathfromNupimportFitSlot# 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]}returndictSubsdefFindTutorialFile(sFileName):sThisScriptFilePath=sys.argv[0]sTutorialDirectory=os.path.split(sThisScriptFilePath)[0]returnos.path.join(sTutorialDirectory,sFileName)defAddHouseToPage(page,sHouseFile):doc=acrobat.documentOpen(sHouseFile)# this is the rect where we want to put the picture of the houserectSlot=acrobat.rect(422,180,180,10)matrixSlot=FitSlot(page.inverseMatrix*rectSlot,doc[0].cropBox*doc[0].defaultMatrix)doc[0].contentsCopyToPage(page,matrixSlot*doc[0].defaultMatrix)doc.close()defDataMailer(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)AddHouseToPage(docNew[i],FindTutorialFile(tupData[i][7]))returndocNew doc=DataMailer(FindTutorialFile('template.pdf'),data)doc.forceVisible()