We have about 500 1 page InDesign files which each need a bit of text added to them in the format:

Completion Year xxxx

The text needs to be right justified and placed below other text boxes which hold information such as client and location, in the same font/format.

Ideally, a script which would add a text box with "Completion Year" and the appropriate date (perhaps taken from an excel or csv file?) would be great.

Failing that, a script that just inserts the text box with "Completion Year" in the correct location on the page and font would also be very helpful.

Any help/insight is appreciated.

ETA: We also have these as PDFs. Will it be easier to add this via script to a pdf vs. InDesign?


1 Answer 1


Thats already a lot you want there. Did you do any prior research or tests?
Anyway I think this is what you want.
It reads a textfile you select. Add your content to each line. Use a paragraph style to set behaviour like alignment and fonts.

  var main = function() {
    // check for active document
    if (app.documents.length < 1) {
      // no doc
    } else {
      // sleect the file
      var file = File.openDialog("Select a textfile", "*.*", false);
      if (file === null) {
        // aborted by user
      // read in the file line per line
      var lines = [];
      while (!file.eof) {
        lines[lines.length] = file.readln();
      file.close(); // always close files

      var doc = app.activeDocument;
      // set the origin to the page
      var curr_origin = doc.viewPreferences.rulerOrigin;
      doc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

      // the locations for the textframe
      var y1 = 0;
      var x1 = 0;
      var y2 = 100;
      var x2 = 100;

      // loop all pages
      for (var i = 0; i < doc.pages.length; i++) {
        var page = doc.pages[i];
        // get the content
        var content = "not enough lines";
        if (lines.length > i) {
          // we still have lines in the file
          content = lines[i];
        // create the textframe
        var tf = page.textFrames.add({
          contents: content,
          geometricBounds: [y1, x1, y2, x2]
        // apply a style by name
        // tf.paragraphs[0].appliedParagraphStyle = doc.paragraphStyles.item("myStyle");
      doc.viewPreferences.rulerOrigin = curr_origin;



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.