Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Explorer ,
Jan 26, 2022 Jan 26, 2022

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.

 

 

TOPICS
Scripting
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 3 Correct answers

Community Expert , Jan 26, 2022 Jan 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.P
...
Translate
Community Expert , Jan 26, 2022 Jan 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

...
Translate
Engaged , Jan 26, 2022 Jan 26, 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
...
Translate
Community Expert ,
Jan 26, 2022 Jan 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);

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 27, 2022 Jan 27, 2022
LATEST

Thank you so much

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2022 Jan 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 )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 27, 2022 Jan 27, 2022

Thank you so much for your response

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 26, 2022 Jan 26, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 27, 2022 Jan 27, 2022

Thank you so much for your response

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2022 Jan 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines