Friday, April 2, 2010

Script for replacing Image from a frame...

Hi All,

I am having an indesign document (indd) file with images and texts. I am using InDesign Server CS4 to run the scripts via SOAP.

My requirement is to replace any of the images from the required frame/s of indesign document through scripting (I already have frame id of which image needs to be replaced). I have written written java-script file (as given below): but when I execute this java-script on InDesign Server via SOAP, I get follwoing error into InDesign Server:

10/03/09 15:15:54 INFO?[javascript] Executing File: \\Server_IP_Address\JavaScript_File_Path\JavaScript_File.js
10/03/09 15:16:01 ERROR [link manager] Link missing.; file:C:/help.gif
10/03/09 15:16:01 ERROR [link manager] Link missing.; file:C:/Documents%20and%20Settings/All%20Users/Documents/My%20Pictures/Sample%2 0Pictures/Water%20lilies.jpg
10/03/09 15:16:01 ERROR [link manager] Link missing.; file:C:/Documents%20and%20Settings/All%20Users/Documents/My%20Pictures/Sample%2 0Pictures/Winter.jpg


Following is the java-script that is being used for replacing image from indd's frame:

var myDocument = app.open(File('//Server_IP_Address/InDesignDocument_File_Path/Sample.indd'));
var tmp_frmid=''1339''; //frame id of which image needs to be replaced.
for (var i=0;i%26lt;myDocument.pages.length;i++)
{
var objPage=myDocument.pages.item(i);
var objPageitems = objPage.pageItems;
try
{
var obj = objPageitems.itemByID(tmp_frmid);
obj.images[0].remove;
obj.appliedObjectStyle = null;
var myImage=obj.place(File('//Server_IP_Address/Images_to_be_reolaced_Path/ImageFile.jpg'));
var old_height = myImage.geometricBounds[2] - myImage.geometricBounds[0];
var new_height = obj.geometricBounds[2] - obj.geometricBounds[0];
var old_width = myImage.geometricBounds[3] - myImage.geometricBounds[1];
var new_width = obj.geometricBounds[1] + ((new_height / old_height) * old_width);
myImage.geometricBounds = [obj.geometricBounds[0] + ''mm'', obj.geometricBounds[1] + ''mm'', obj.geometricBounds[2] + ''mm'', new_width + ''mm''];
var diff = obj.geometricBounds[1] - myImage.geometricBounds[1];
myImage.move( undefined, [diff,0] );
break;
}
catch(e)
{
}
}
myDocument.save('//Server_IP_Address/InDesignDocument_File_Path/Sample.indd');
var previewFile = File('//Server_IP_Address/Images_to_be_reolaced_Path/ImageFile.jpg');
app.jpegExportPreferences.jpegQuality[''JPEGOptionsQuality.low''];
app.documents.item(0).exportFile(ExportFormat.jpg, previewFile);
myDocument.close();

I have very urgent requirement; if anyone have any idea; please suggest me. \

It would be highly appreciable.

Kind Regards,

Prashant.

  • eye shadow
  • No comments:

    Post a Comment