Before I explain what I need to happen, I think it'd be helpful to explain the document I'll be working on:
With InDesign, using the data merge functionality, I will create a document where each spread will be the front and back page of a product spec sheet (letter size, 2-sided).
What I'm hoping a script can do, is to export every spread as it's own PDF, and name the PDFs based on the model number of the product shown on each spread.
So for example, let's say the data merge was 25 records. That'd be 25 spreads (50 pages), starting on page 2. The export would create a PDF of pages 2-3, a PDF of 4-5, of 6-7, and so on. The export process would also extract the model number which would be consistently located in a table on left page, and use the model number to name the PDF it's creating.
It seemed more doable when it was just in my head. Now that I've typed it out I'm not as optimistic. But I'm also a scripting simpleton so hopefully any skilled folks can chime in on the viability of the idea.
Thanks!
*edit to say that I used 25 records just as an example. The project will be for hundreds of spec sheets hence the interest to data merge and automate what I can.
So far I've just worked on verifying I could use InDesign's data merge to create spreads and not just single pages.
I did look at a script I got help on here that while was a very different process, it did include a step that found cell contents based on the text in the title cell. That's what made me think it'd be possible to extract the model number and use it to name each file.
Screenshot of spread showing the data merge tags
Screenshot showing simple table idea
Screenshot showing table idea as referenced in my last comment
Here is the variant of the script which takes the names of the PDF files from first cell of second row of first table on the hidden layer with name 'Hidden Text Test':
var doc = app.activeDocument;
var pdf_preset = app.pdfExportPresets[0]; // High Quality Print
var folder = doc.filePath // save into the same folder as the active document
var hidden_layer_name = 'Hidden Text Test';
var table, layer_name, pdf_file_name, page_num;
var tables = doc.stories.everyItem().tables.everyItem().getElements();
for (var i=0; i<tables.length; i++) {
table = tables[i];
layer_name = table.parent.itemLayer.name;
if (layer_name != hidden_layer_name) continue;
page_num = parseInt(table.parent.parentPage.name);
pdf_file_name = table.rows[1].cells[0].contents;
export_spread(page_num, folder, pdf_file_name);
}
function export_spread(page, folder, name) {
var pdf_file = File(folder + '/' + name + '.pdf');
app.pdfExportPreferences.pageRange = page + '-' + (page+1);
doc.exportFile(ExportFormat.pdfType, pdf_file, false, pdf_preset);
}