1 Reply Latest reply on Aug 29, 2013 12:34 AM by Manan Joshi

    Pulling data from a specific text container [js]

    Really Randy Level 1

      I have to frequently make a hundred or so PDF overlays for video. I used a template with data merge to make a multi-page PDF file of all the overlays. I then run a jscript that saves each page individually and does a search for a specific string from which to name the individual PDF files. I had lot's of help from members of this forum to write this particular script, BTW.


      Here is the script:


      var destinationFolder = Folder.selectDialog ("Choose a Folder");


      var myPDFExportPreset = app.pdfExportPresets.item("TVoverlay");


      doc = app.activeDocument;

      doc.sections.everyItem().includeSectionPrefix = false;

      app.findTextPreferences = null;

      app.findTextPreferences.findWhat = 'AutoOffers_^9^9^9^9';

      found = doc.findText();

      for (i = 0; i < found.length; i++ ){

          f = File (destinationFolder + "/" + found[i].contents + '.pdf');

          app.pdfExportPreferences.pageRange = found[i].parentTextFrames[0].parent.name;

          doc.exportFile (ExportFormat.pdfType, f, false, myPDFExportPreset);



      The bolded lines are the ones I have a question about. These lines find something that starts with "AutoOffers_" and replace the next four characters with whatever comes next in the text box on that particular page. Every time the naming format changes I have to edit the script. The file name is always in the same text box with the same data merge field name "jobnum". Please see the screenshot below:

      Screen shot 2013-07-23 at 11.01.23 AM.png


      What you see in the screenshot is the data merge panel with three of the generated pages. The "jobnum" data field is a non-printing element just off the page in the slug area.


      Is there a way I can target this specific (jobnum) field or text container to extract the file name for the generated PDF file? Isthis what the "Script Label" panel is for? If so, would that work?


      Thank you all,


        • 1. Re: Pulling data from a specific text container [js]
          Manan Joshi Level 4

          What you could do is while you place the jobnum placeholder inside the textframe, just add a scriptlabel to that textbox using the script label palette or using a simple script to find this textframe and adding scriptlabel to it.


          Once the merge is done you can then iterate through all the textframes in the merged document and match the scriptlabel with the one you used to get to the desired frame and then using the parentStory.contents to get the content that will give you the text you are interested in.