Copy link to clipboard
Copied
I am adding color images to an idml file like this:
var docArray = [
"idml template name",
];
for (x = 0; x < docArray.length; x++) {
// Open IDML file
var idmlDocName = "folderName/" + docArray[x] + ".idml";
try {
var idmlDoc = app.open(idmlDocName);
// Modify idml
var myStories = idmlDoc.stories.everyItem().getElements();
for (i = 0; i < myStories.length; i++) {
var myTextFrames = myStories[i].textContainers;
for (j = 0; j < myTextFrames.length; j++) {
switch(myTextFrames[j].contents) {
case "FLS_IMG_TAG;1;1;1":
myTextFrames[j].place(File("folderName/imgName.jpg"));
myTextFrames[j].fit(FitOptions.CONTENT_TO_FRAME);
myTextFrames[j].fit(FitOptions.PROPORTIONALLY);
myTextFrames[j].fit(FitOptions.CENTER_CONTENT);
break;
}
}
}
//Export the document as PDF (fill in a valid file path).
var pdfDocName = "folderName/" + docArray[x] + " - edited.pdf";
idmlDoc.exportFile(ExportFormat.pdfType, new File(pdfDocName));
} catch (error) {
alert(error + " docName: " + docArray[x]);
}
}
The images are in color and I want to programatically change them to black and white. Is it possible to do that before or after exporting to PDF?
Copy link to clipboard
Copied
You could do one thing:
Via bridgeTalk you could open PhotoShop, open the images in PhotoShop, convert and save it to grayscale.
Update the links in your InDesign document. Then export to PDF.
See documentation in the JavaScript Tools Guide CC.pdf, chapter:
5 Interapplication Communication with Scripts
Pages 166 to 193
Especially pages 179 pp
BridgeTalk Class
BridgeTalk message object
Also see into the DOM documentation for PhotoShop.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
BridgeTalk is a new concept for me. I'll take a look but I think changing the colorspace looks pretty straight forward.
Copy link to clipboard
Copied
I found the answer after a little more digging.
app.pdfExportPreferences.pdfColorSpace = PDFColorSpace.CMYK;
if (pdfDocName.indexOf("BW") !== -1) { //true
app.pdfExportPreferences.pdfColorSpace = PDFColorSpace.GRAY;
}
Copy link to clipboard
Copied
But wouldn't that convert all elements on a page to grayscale?
( Thought, you would like to do this for placed images only. )
FWIW: You can get better quality if you include PhotoShop into the workflow.
But this will require image contents evaluation like statistics on individual gradation and so forth.
PhotoShop is able to do that.
If you want convert all pages you could also look into an Acrobat Pro DC workflow.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
"I found the answer after a little more digging."
That's by far not the whole picture. You also need a decent color management setting for your document, a loaded *.csf file where all the conversion paramenters are stored before you open your IDML files.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
If you are trying to convert the entire PDF to grayscale, you would have to also include a gray destination profile. The PDFColorSpace property refers to the Output>Color Conversion setting in the UI, which is a bit confusing. So this exports a PDF/X-4 with a conversion to Dot Gain 20%
var f = new Folder(Folder.desktop)
var doc = app.documents.item(0);
var thePath = f + "/" + doc.name + ".pdf";
var preset=app.pdfExportPresets.itemByName("[PDF/X-4:2008]");
//PDF Export Prefs
with(app.pdfExportPreferences){
pageRange = PageRange.ALL_PAGES;
pdfColorSpace = PDFColorSpace.GRAY;
pdfDestinationProfile = "Dot Gain 20%";
pdfXProfile:"Dot Gain 20%";
}
doc.exportFile(ExportFormat.pdfType, File(thePath));