Thanks for that Dave.
With the two Regex lines commented out and your suggestion in place I get single page PDFs named like this: myBaseName + "-" + "myPageName" + "_ned" + ".pdf", ie "BaseNameOfMagazine-26_ned.pdf".
No idea where "_ned" came from.
Sorry for not being specific enough with my first post - I'd not realised the complexity of the script - particularly after easily modding it to specify the joboptions with a bit of Google, the InDesign Scripting Guide and InDesign Scripting Reference.
The script currently is as follows. (Commented modifications to otherwise working script are between lines 39-50.) Please let me know if there's any other information I should be supplying.
Thanks again for your help thus far
//ExportEachPageAsPDF.jsx
//An InDesign CS2 JavaScript
//Exports each page of an InDesign CS document as a separate PDF to
//a selected folder using specific PDF export settings.
//Display a "choose folder" dialog box.
if(app.documents.length != 0){
var myFolder = Folder.selectDialog ("Choose a Folder");
if(myFolder != null){
myExportPages(myFolder);
}
}
else{
alert("Please open a document and try again.");
}
function myExportPages(myFolder){
var myPageName, myFilePath, myFile;
var myDocument = app.activeDocument;
var myDocumentName = myDocument.name;
//This next line sets the PDF export Setting
var myPDFExportPreset = app.pdfExportPresets.item("Press Quality")
var myDialog = app.dialogs.add();
with(myDialog.dialogColumns.add().dialogRows.add()){
staticTexts.add({staticLabel:"Base name:"});
var myBaseNameField = textEditboxes.add({editContents:myDocumentName, minWidth:160});
}
var myResult = myDialog.show({name:"ExportPages"});
if(myResult == true){
var myBaseName = myBaseNameField.editContents;
//Remove the dialog box from memory.
myDialog.destroy();
for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){
myPageName = myDocument.pages.item(myCounter).name;
app.pdfExportPreferences.pageRange = myPageName;
//The name of the exported files will be the base name + the
//page name + ".pdf".
//If the page name contains a colon (as it will if the document
//contains sections),
//then remove the colon.
//[g] next two line commented out, trying Dave Saunders' suggestion
//var myRegExp = new RegExp(":","gi");
//myPageName = myPageName.replace(myRegExp, "_");
//[g] insert DS' suggestion:
myParts = myPageName.split(":");
try {
myParts[1] = ("00" + myParts[1]).slice(-3);
myPageName = myParts.join("_");
} catch(e) {
myPageName = ("00" + myPageName).slice(-3);
}
//[g] end mod
myFilePath = myFolder + "/" + myBaseName + "-" + myPageName + ".pdf";
myFile = new File(myFilePath);
myDocument.exportFile(ExportFormat.pdfType, myFile, false, myPDFExportPreset);
}
}
else{
myDialog.destroy();
}
}