Skip to main content
Evan vR
Participant
September 15, 2021
Answered

Using text variables to create file name on export

  • September 15, 2021
  • 3 replies
  • 7734 views

Hello,

 

I'm pretty much brand new to JavaScript so forgive me if this seems like a dumb question. But I've got an export script to create two files with specific names from a single InDesign document. The name of the InDesign file is a constant in both files however one needs to contain a variable customer name and the other will always contain "FOX".

 

The script is currently exporting the files correctly, as well as the naming conventions for everything except the customer name. Currently I have the customer name set up as a text variable in my InDesign template. When I go to export all I get for the customer name pdf is the InDesign file name plus [object TextVariable] instead of the definition I give the variable itself.

What I would like to have on export is

A123456 CUSTOMER.pdf (Customer of course being replaced with the text variable definition)

A123456 FOX.pdf

I'm probably missing something here but I can't figure out what. I've attached some screenshots here for the naming section of the script plus the result. Any advice would be appreciated. Thanks!

  

This topic has been closed for replies.
Correct answer TᴀW

It's not free, but Extract Pages - Id-Extras.com (an InDesign add-on/script) does everything you want. It will let you set up, say a GREP find to find whatever text you want on the page, and then create PDFs from each page, with that found text (plus any prefixes and suffixes you want) as the file name... and many more options....

3 replies

Participating Frequently
July 3, 2023

There is an amazing script made by Mars Premedia that might work for you. It can be used to export PDFs, JPGs & PNGs by extracting text (visible or not) with an applied paragraph and/or character style. The first time I used this script, it paid for itself! It's just that helpful. It's like having an extra employee without having to pay them. As of this posting, there is a 30-day free trial. At least try it. You won't be sorry.

As of this posting, a single-user perpetual license can be purchased by following the link below. Pay once, no subscription, use forever.

Export Named Pages Script:

https://www.marspremedia.com/software/indesign/export-named-pages

There are also 2 YouTube video tutorials created by the maker of this product. The first is the original script & the second video contains updated material from one of the more recent updates:

https://www.youtube.com/watch?v=3ldKqt1p14k
https://www.youtube.com/watch?v=DpBKyBRBJtw

One more thing. Look at his changelog! He continues to update the script with some very valuable new functionalities based on the feedback he gets from users. A scripting genius with superb customer support! I believe he really cares about his work and how it affects people's lives & I really appreciate that.

Legend
September 16, 2021

Hello @Evan vR,

 

Give this a try, as it worked for me returing the text from a Type: Custom Text  text variable...

var myCustomerName = app.activeDocument.textVariables.itemByName('CustomerName').variableOptions.contents;

 

Regards,

Mike

m1b
Community Expert
Community Expert
September 16, 2021

Thanks Mike, I reckon your way is better, because it means that you don't have to have used the variable anywhere. Nice. - Mark

m1b
Community Expert
Community Expert
September 15, 2021

Hi @Evan vR, I haven't tested, but try this:

var myCustomerName = app.activeDocument.textVariables.itemByName('CustomerName').associatedInstances[0].resultText;

Let me know if it doesn't work and I'll actually try it. 🙂 You can learn more here.

- Mark