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

Script to load some docs and merge to pdf

Explorer ,
Oct 08, 2021 Oct 08, 2021

Hi

 

I don't really know Javascript, so before I start trying to pick it up (I'm from a vb.net background) I wondered if someone could confirm this is the kind of thing I can do with it.

 

I have 32 different Indesign docs, each 2 pages long with a pdf placed in the background of each page and various text merge boxes. Each is linked to a different csv address file and I produce pdfs with variable data via the Data Merge screen.

 

It's very tedious having so many different docs manually, but the layouts are slightly different and so having them all separate seemed to be the easiest way to keep control of things (especially for those times when my client wishes to change the background pdfs on some of them).

 

I'd like to come up with a script which would:

1. Loop through all the documents, loading them one at a time

2. Confirm any messages about the text address file having changed when the doc is loaded

3. Check if the associated data file exists - if not, abort and go to the next document

4. If the text file exists, do a data merge to a pdf in specified folder.

 

Is this kind of thing possible with an Indesign script? - thanks for reading.

TOPICS
Scripting
1.1K
Translate
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 ,
Oct 08, 2021 Oct 08, 2021

Hi @ashleyw42715064,

All this sounds doable. I will list some pointers for each subtask that might help you search and investigate

  1. This is easy, you can loop over the documents collection found on the app object.
  2.  Shut off the userInteractionLevel of the script so that you don't get any alerts like missing font or links. Open the document and the loop over all the links and see if the csv link is missing or modified and do the needful
  3.  Covered in point 2
  4.  Do the merge by calling the merge method.

You will get snippets for much of these tasks on the forum, get it and put it together, if you face issues just post back we are here to help.

For JS DOM documentation you can refer to the following link

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html

-Manan

Translate
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 ,
Oct 11, 2021 Oct 11, 2021

Thanks both for your posts - sounds good, I'll check out the link.

 

I know in the past whenever I've tried to do much with mail-merging I run into difficulties because it's not really what Indesign is intended form, so it's good to know I'm not asking for the impossible.

 

I'll try to get some time on this soon and see how far I can get before asking for help!

Translate
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 ,
Oct 10, 2021 Oct 10, 2021

I don't really know Javascript, so before I start trying to pick it up (I'm from a vb.net background)

 

If you know VB you won't have many problems with javaScript. There are many similarities, they're both procedurel languages.

 

P.

Translate
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 ,
Oct 29, 2021 Oct 29, 2021

Thanks for the info, I'll check that out.

 

In the end I went with a bit of an odd solution:

 

1. All my data is in MS Access, so I used some VBA to loop through the data and see which categories had a count > 0 and export them as a csv file to match the name the indesign file was expecting.

 

2. I then created a text file using VBA which would add the appropriate lines for each data source. It just repeats the same lines for each document it needs to open

 

3. I export the text file with a jsx suffix (overwriting the previous script file), then run it from Indesign

 

Below is the sample code for a couple of docs. I don't think it's the most elegant solution, but it does seem to work!

 

var template = app.open (File ('<my indesign file 1>.indd'));
var myFileName = app.activeDocument.name.split('.')[0];
var myPath = 'c:/ash/test ind/UK/' + myFileName +'.pdf'
app.activeDocument.dataMergeProperties.updateDataSource();
app.activeDocument.dataMergeProperties.mergeRecords();
app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;
myFinalFile = new File(myPath);
app.activeDocument.exportFile(ExportFormat.PDF_TYPE, myFinalFile, false );
template.save();
template.close();
app.activeDocument.close(SaveOptions.no);

var template = app.open (File ('<my indesign file 2>.indd '));
var myFileName = app.activeDocument.name.split('.')[0];
var myPath = 'c:/ash/test ind/UK/' + myFileName +'.pdf'
app.activeDocument.dataMergeProperties.updateDataSource();
app.activeDocument.dataMergeProperties.mergeRecords();
app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;
myFinalFile = new File(myPath);
app.activeDocument.exportFile(ExportFormat.PDF_TYPE, myFinalFile, false );
template.save();
template.close();
app.activeDocument.close(SaveOptions.no);


<repeat as required>
Translate
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 ,
Oct 31, 2021 Oct 31, 2021

Yes this could definitely be written. I have a script on my shelf that I don't make publicly available via my website but DM me and I can send you what I have.

 

There is also a script from Peter Kahrel called batch convert - this script will parse all ID files in a folder (and its subfolders if necessary) and then export to another file - including to an INDD file again, but while that is happening, allows a script to run. So you could use Peter's script to loop through all documents, and use a snippet of data merge script that runs a data merge on the currently open file.

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!
Translate
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 ,
Oct 31, 2021 Oct 31, 2021
LATEST

Hi Colin

 

Thanks for your post - I've read some of your other posts in the past and it's always been useful and taught me a few things.

 

I'm going to stick with the solution I've got for the moment, but it's bound to be useful at some point to have the whole thing running from Indesign instead of Access VBA. Anyone who doesn't have to do the data prep in Access as I have to will certainly be better off going down that route.

Translate
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