Skip to main content
Known Participant
January 26, 2022
Answered

Script to save the file in the 3 different formats (.indd, .idml, and .pdf )

  • January 26, 2022
  • 4 replies
  • 2721 views

Hello All,

 

I am struggling to write a script to save the ".indd" file into other two formats ".idml" and ".pdf".

For Example:

1) File Name " Artwork.indd" is the source file. I need to change some contents in the file.

2) After the changes, I need to save the existing "Artwork.indd" file in the default location.

3) Also, I need to save the file as "Artwork.idml" and "Artwork.pdf" in the same existing folder.

 

Please help me to figure out the script to overcome this situation.

 

 

This topic has been closed for replies.
Correct answer SumitKumar

Hi @Surya24 ,

 

 

var pdfExportPreset = ""; //Kindly assign name of the pdf preset.
if (!(app.documents.length)) {
    alert("Open your indesign file.");
    exit(0);
}
var doc = app.documents[0];
doc.save();

var docFile = new File(doc.fullName);
var docPath = docFile.parent;
var docName = doc.name.replace(/\.indd$/i, "");
var idmlFile = new File(docPath + "/" + docName + ".idml");
var pdfFile = new File(docPath + "/" + docName + ".pdf");

doc.exportFile(ExportFormat.INDESIGN_MARKUP, idmlFile);
if (pdfExportPreset != "") {
    doc.exportFile(ExportFormat.PDF_TYPE, pdfFile, false, pdfExportPreset);
}
else {
    doc.exportFile(ExportFormat.PDF_TYPE, pdfFile, true);
}

 

 

4 replies

Jumpenjax
Community Expert
Community Expert
January 27, 2022

Why not use the Package feature it does all of them in a neat little folder. It also will point out any potential problems.

Lee- Graphic Designer, Print Specialist, Photographer
SumitKumar
SumitKumarCorrect answer
Inspiring
January 27, 2022

Hi @Surya24 ,

 

 

var pdfExportPreset = ""; //Kindly assign name of the pdf preset.
if (!(app.documents.length)) {
    alert("Open your indesign file.");
    exit(0);
}
var doc = app.documents[0];
doc.save();

var docFile = new File(doc.fullName);
var docPath = docFile.parent;
var docName = doc.name.replace(/\.indd$/i, "");
var idmlFile = new File(docPath + "/" + docName + ".idml");
var pdfFile = new File(docPath + "/" + docName + ".pdf");

doc.exportFile(ExportFormat.INDESIGN_MARKUP, idmlFile);
if (pdfExportPreset != "") {
    doc.exportFile(ExportFormat.PDF_TYPE, pdfFile, false, pdfExportPreset);
}
else {
    doc.exportFile(ExportFormat.PDF_TYPE, pdfFile, true);
}

 

 

-Sumit
Surya24Author
Known Participant
January 27, 2022

Thank you so much for your response

Community Expert
January 26, 2022

Hi Vaithiyanathan J,

for the file argument, the second one of method exportFile() , you could use the document itself as a starting point.

 

var doc = app.activeDocument;
var docFile = File( doc.fullName );
var docPath = docFile.parent;

var idmlFileName = doc.name.replace(/\.indd$/i , ".idml" );
var idmlFile = File( docPath +"/"+idmlFileName );

var pdfFileName = doc.name.replace(/\.indd$/i , ".pdf" );
var pdfFile = File( docPath +"/"+pdfFileName );

 

Note: Make sure that the InDesign document is already saved at least once so that you will not get an error at doc.fullName. Also note, that there is a second method for exporting files: asynchronousExportFile() that also takes a file as the second argument.

 

DOM documentation compiled by Gregor Fellenz:

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

 

Regards,
Uwe Laubender

( ACP )

Surya24Author
Known Participant
January 27, 2022

Thank you so much for your response

BarlaeDC
Community Expert
Community Expert
January 26, 2022

Hi,

 

In the script you want to do the following

 

for IDML:

Use the exportFile command and pass ExportFormat.INDESIGN_MARKUP

 

for PDF:

Use the exportFile commend and pass ExportFormat.PDF_TYPE.

And you need to specify a PDFExportPreset, you can see the ones in the File->Adobe PDF Presets menu.

 

link to the documentation - https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Document.html#d1e49413__d1e53790

 

// code would be something like

app.activeDocument.exportFile ( ExportFormat.PDF_Type, "path_to_export_to", false, PDFExportPreset, "version", true);

 

Surya24Author
Known Participant
January 27, 2022

Thank you so much