• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Using text variables to create file name on export

Community Beginner ,
Sep 15, 2021 Sep 15, 2021

Copy link to clipboard

Copied

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!

Screen Shot 2021-09-15 at 3.41.23 PM.png

Screen Shot 2021-09-15 at 3.29.29 PM.png

  

TOPICS
How to , Import and export , Scripting , Type

Views

2.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Advisor , Sep 15, 2021 Sep 15, 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

Votes

Translate

Translate
People's Champ , Mar 23, 2023 Mar 23, 2023

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....

Votes

Translate

Translate
Community Expert ,
Sep 15, 2021 Sep 15, 2021

Copy link to clipboard

Copied

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 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Sep 15, 2021 Sep 15, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 15, 2021 Sep 15, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

Thanks Mike,

 

That worked like a charm!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 22, 2023 Mar 22, 2023

Copy link to clipboard

Copied

Jumping on this a couple years later to ask, would this be a good way to custom-name data merged documents? I'm doing a data merge and I want to export and name each merge result as its own document. The challenge is, when I run the merge each result just gets a digit. So if the master is "MyDoc.indd", then I get "MyDoc1.indd", "MyDoc2.indd". I could work with this by changing the file name on export to found text, possibly using the above script with a modification to using "found text" rather than a preset variable.

 

Example: The merge is "Name: <<fname>> <<lname>>"

Result 1 is: "Name: John Smith"

 

So script would:

1. GREP find: (?<=Name: )(\w.+ \w.+)

2. Export to PDF: "[foundtext].pdf" resulting in "John Smith.pdf"

 

Would that be possible and/or the best way to do it?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Mar 22, 2023 Mar 22, 2023

Copy link to clipboard

Copied

Hello @defaultu0e43kqloi6n,

 

If you goal is to export individual pdfs with unique file names from a merged document, take a look at the post below...

https://community.adobe.com/t5/indesign-discussions/unique-file-names/m-p/11965769

Regards,

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 23, 2023 Mar 23, 2023

Copy link to clipboard

Copied

Hmm, thanks that's in the right direction, but it looks to want to create a separate PDF from each page. A single record from my data merge takes up 240 pages (it's a book-length document with a lot of custom fields throughout). I'm merging and exporting one record at a time, so automating the steps of File>Export>Interactive PDF>Type in File Name>Export seems like a small thing to automate, but it will save a lot of time over hundreds of records and also help avoid human error in mixing up or mistyping the names.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 23, 2023 Mar 23, 2023

Copy link to clipboard

Copied

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....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 07, 2023 Apr 07, 2023

Copy link to clipboard

Copied

Sorry for the delayed response, but this looks like exactly what I need, thank you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 03, 2023 Jul 03, 2023

Copy link to clipboard

Copied

LATEST

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.

JavaScript for InDesign exports pages using a unique name drawn from each page's content. Video tutorial is Windows. Script works the same both macOS and Windows. - Name by paragraph style or character style - Name by image, stacking order or object style - Prefix and suffix using variable ...
JavaScript for InDesign exports pages using unique names drawn from each page's content. Video tutorial is Windows. Script works the same both macOS and Windows. This is an update to an earlier video: https://youtu.be/3ldKqt1p14k When I made the first video, users contacted me with ideas for more

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines