Skip to main content
dublove
Legend
Feb 5, 2025 1:21 PM UTC
Answered

Can today's date be automatically added before the file name when export PDF?

Can today's date be automatically added before the file name when export PDF?
For example, my file name: myFile.indd
every time to add the day before the date, such as: 2025-02-05-myFile.pdf

 

I often change the ID file name directly, a little impatient.

 

I use a bit too many templates and sometimes I need to modify them temporarily.

Directly with the script export, can not temporarily modify the template.
Can you automatically modify the name when exporting?
Then only call the ID software comes with the interface to export PDF?

Anantha Prabu G
Anantha Prabu GCorrect answer
Legend
Feb 7, 2025 11:20 AM UTC

Very much looking forward to it.
Thanks.


var myDocument = app.activeDocument;
var myFileName = myDocument.name.replace(/\.indd$/, ''); // Remove the .indd extension
var myDate = new Date();
var myYear = myDate.getFullYear();
var myMonth = ("0" + (myDate.getMonth() + 1)).slice(-2); // Add leading zero
var myDay = ("0" + myDate.getDate()).slice(-2); // Add leading zero
var myFormattedDate = myYear + "-" + myMonth + "-" + myDay;
var myPDFFile = new File(myDocument.filePath + "/" + myFormattedDate + "-" + myFileName + ".pdf");

// Create a dialog for selecting the PDF export preset
var myDialog = new Window('dialog', 'Select PDF Export Preset');
myDialog.orientation = 'column';
myDialog.alignChildren = 'left';

var myDropdown = myDialog.add('dropdownlist', undefined, app.pdfExportPresets.everyItem().name);
myDropdown.selection = 0;

var myButtonGroup = myDialog.add('group');
myButtonGroup.orientation = 'row';
myButtonGroup.add('button', undefined, 'OK', {name: 'ok'});
myButtonGroup.add('button', undefined, 'Cancel', {name: 'cancel'});

if (myDialog.show() == 1) {
    var myPDFExportPreset = app.pdfExportPresets.item(myDropdown.selection.text);
    myDocument.exportFile(ExportFormat.PDF_TYPE, myPDFFile, false, myPDFExportPreset);
} else {
    alert('Export canceled');
}
Design smarter, faster, and bolder with InDesign scripting.

15 replies

Anantha Prabu G
Legend
Feb 5, 2025 3:50 PM UTC

Hi @dublove 

var myDocument = app.activeDocument;
var myFileName = myDocument.name.replace(/\.indd$/, ''); // Remove the .indd extension
var myDate = new Date();
var myYear = myDate.getFullYear();
var myMonth = ("0" + (myDate.getMonth() + 1)).slice(-2); // Add leading zero
var myDay = ("0" + myDate.getDate()).slice(-2); // Add leading zero
var myFormattedDate = myYear + "-" + myMonth + "-" + myDay;
var myPDFFile = new File(myDocument.filePath + "/" + myFormattedDate + "-" + myFileName + ".pdf");

var myPDFExportPreset = app.pdfExportPresets.item("[High Quality Print]"); // You can change the preset if needed
myDocument.exportFile(ExportFormat.PDF_TYPE, myPDFFile, false, myPDFExportPreset);
Translate
Design smarter, faster, and bolder with InDesign scripting.
dublove
dubloveAuthor
Legend
Feb 6, 2025 9:48 AM UTC

I can't seem to set the export option.

Third party scripts should be difficult to implement.

Hoping that Adobe will add official functionality.

 

Translate
Robert at ID-Tasker
Legend
Feb 6, 2025 10:57 AM UTC

@dublove

 

I think there is something wrong with the name of the PDF export profile you've entered?

 

Translate
Robert at ID-Tasker
Legend
Feb 5, 2025 1:45 PM UTC
Robert at ID-Tasker
Legend
Feb 5, 2025 1:41 PM UTC

You mean "when exporting"?

 

It should be achievieable with adding event listener.

 

Translate