Skip to main content
dublove
Legend
February 5, 2025
Answered

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

  • February 5, 2025
  • 3 replies
  • 1054 views

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?

Correct answer Anantha Prabu G

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');
}

3 replies

Anantha Prabu G
Legend
February 5, 2025

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);
Design smarter, faster, and bolder with InDesign scripting.
dublove
dubloveAuthor
Legend
February 6, 2025

Thank you very much

Sorry ,sorry ,It's export PDF, I wrote import by mistake.

I know how to do it, I think I've seen who seems to have written scripts for exporting PDF interfaces.
Might be able to write this current script with that one.

 

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
Legend
February 6, 2025

Yes, you're correct!

Design smarter, faster, and bolder with InDesign scripting.
Robert at ID-Tasker
Legend
February 5, 2025
Robert at ID-Tasker
Legend
February 5, 2025

You mean "when exporting"?

 

It should be achievieable with adding event listener.