Skip to main content
Inspiring
June 18, 2013
Answered

Export all pages to JPG

  • June 18, 2013
  • 1 reply
  • 1458 views

Hi friends

I use to write scripts for Photoshop, Bridge and Illustrator. But it´s my firt time writting scripts to Adobe InDesign (and my first to this forum too). I´m accustomed with the JavaScript referece document of that 3 softwares, so I´m getting a direct help via the "Object Model Viewer" inside Extended Script Toolkit for writting with InDesign.

I want to export all the pages of my document using JPG as file format. So I set the properties to an instance of JPEGExportPreference and would like to use this configuration to export all the pages. Am I right to use the method app.activeDocument.exportFile() ??

Because I did not find a place to declare the method to read my JPG preference. It´s also getting an error page range was not set. Could you analyse my code and see what I´m missing?

Thank you very much:

var myDoc = app.activeDocument;

 

var fName = myDoc.name.slice (0, myDoc.name.lastIndexOf ("."));


var oFolder = new Folder (myDoc.filePath + "/" + fName + " (Exported)");

if (! oFolder.exists){

   oFolder.create();

};

var fOutput = new File (oFolder + "/" + fName + ".jpg");

var opJPG = new JPEGExportPreference();

opJPG.antiAlias = true;

opJPG.embedColorProfile = true;

opJPG.exportResolution = 300;

opJPG.jpegColorSpace = JpegColorSpaceEnum.RGB;

opJPG.jpegExportRange = ExportRangeOrAllPages.EXPORT_ALL;

opJPG.jpegQuality = JPEGOptionsQuality.HIGH;

opJPG.jpegRenderingStyle = JPEGOptionsFormat.BASELINE_ENCODING;

opJPG.simulateOverprint = true;

opJPG.useDocumentBleeds = false;

myDoc.exportFile(ExportFormat.JPG, fOutput, false);

This topic has been closed for replies.
Correct answer Jongware

Gustavo, other than in Illustrator (don't know about PS and Bridge), in InDesign scripts you cannot "create" new objects using this notation:

var opJPG = new JPEGExportPreference();

Try a with .. statement instead to directly modify the existing object:

with (app.jpegExportPreferences)

{

  antiAlias = true;

  embedColorProfile = true;

  .. etc.

}

(I know, there are lots of articles that claim "with statement considered harmful", but for this particular case I don't see why , as it is just a shortcut for writing

app.jpegExportPreferences.antiAlias = true;

app.jpegExportPreferences.embedColorProfile = true;

.. app.jpegExportPreferences.etc.

.. and so on.)

1 reply

Community Expert
June 18, 2013

@Gustavo – see the following function by Manu at www.hilfdirselbst.ch:

http://www.hilfdirselbst.ch/gforum/gforum.cgi?post=496459#496459

For DOM documentation see:

http://www.jongware.com/idjshelp.html

Uwe

Inspiring
June 19, 2013

Hi Laubender

Thank you very much for the informations.

I analyzed the Manu´s function and it has near the same parameters as what I´ve wrote (he, at true, exports a range of pages in the main function).

In my side, If I run my own code (as shown in the fist message here), then InDesign returns this error: "Failed to export the JPEG file. Invalid page number specified."

But I´m telling to export all pages!! hehe

Am I missing anything?

Thank you very much for the help.

Gustavo.

Jongware
Community Expert
JongwareCommunity ExpertCorrect answer
Community Expert
June 19, 2013

Gustavo, other than in Illustrator (don't know about PS and Bridge), in InDesign scripts you cannot "create" new objects using this notation:

var opJPG = new JPEGExportPreference();

Try a with .. statement instead to directly modify the existing object:

with (app.jpegExportPreferences)

{

  antiAlias = true;

  embedColorProfile = true;

  .. etc.

}

(I know, there are lots of articles that claim "with statement considered harmful", but for this particular case I don't see why , as it is just a shortcut for writing

app.jpegExportPreferences.antiAlias = true;

app.jpegExportPreferences.embedColorProfile = true;

.. app.jpegExportPreferences.etc.

.. and so on.)