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

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

Explorer ,
Jan 26, 2022 Jan 26, 2022

Copy link to clipboard

Copied

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

Views

1.6K

Translate

Translate

Report

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
...

Votes

Translate

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

...

Votes

Translate

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
...

Votes

Translate

Translate
Community Expert ,
Jan 26, 2022 Jan 26, 2022

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Thank you so much

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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 )

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thank you so much for your response

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thank you so much for your response

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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