0

I'm quite a rookie in developping Javascript for Illustrator and I need to optimize the printing actions using Javascript. I'm working on Mac OSX using Illustrator and I have to print Paper and Transparent Films from the same network printer on different trays. I've written a Javascript code and it works... only on the last selected printer in Illustrator. I can select print options for every parameter available in Illustrator print dialog box BUT trays are parts of the printer settings out of Illustrator and I can't define which tray it has to be printed on in Javascript. I've tried to duplicate my printer in OSX and force the setup on the specific transparent tray but It does not work as the script always prints on the last used printer tray selected in Illustrator.

Printer List in OSX:

Printer List in OSX

Preset for Paper:

Preset for Paper

Preset for Transparent Films:

Preset for Transparent Films

Paolo Mossini
  • 1,064
  • 2
  • 15
  • 23
  • Hello there and welcome, i think this might be easier to solve, if you can show us your Javascript so far. – Clomez Feb 26 '20 at 13:47
  • Sorry if the code appears to be... singular but I'm brand new in coding without no training or formation... only self-learning... – Maëlle Deprez Feb 26 '20 at 14:00

1 Answers1

0
var Doc = app.activeDocument;

app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;

var fileref = Doc.name;

var PrintRicoh = app.printerList[1].name;
var PrintRicohFilm = app.printerList[3].name;
var PaperA3 = printerList[1].printerInfo.paperSizes[0];

alert (PrintRicoh);
alert (PrintRicohFilm);

var PrintBox = new Window('dialog', "Print Dialog Box",);

FileNameBox = PrintBox.add ('panel', undefined, "File Name");
FileNameBoxgroup = FileNameBox.add('group', undefined);
FileNameBoxgroup.orientation = 'row';
FileNameBoxgroup.alignment = [ScriptUI.Alignment.LEFT,ScriptUI.Alignment.TOP]; 
var FileNametxt = FileNameBoxgroup.add('statictext', undefined, "File Name : ");
FileNametxt.size = [ 105,20 ];
var FileName = FileNameBoxgroup.add ('edittext', [undefined, undefined, 200, 20], (fileref) );
FileName.active = false;

PrintBox.panel = PrintBox.add ('panel', undefined, "Printer Destination");
PrintBox.panel.group = PrintBox.panel.add('group', undefined);
PrintBox.panel.group.orientation = 'row';
PrintBox.panel.group.alignment = [ScriptUI.Alignment.LEFT, ScriptUI.Alignment.TOP];
var PrinterNametxt = PrintBox.panel.group.add('statictext', undefined, "Printer Name : ");
PrinterNametxt.size = [ 105,20 ];
var PrinterName = PrintBox.panel.group.add ('edittext', [undefined, undefined, 200, 20], (PrintRicoh));
PrinterName.active = false;

PaperSizeBox = PrintBox.add ('panel', undefined, "Paper Size");
PaperSizegroup = PaperSizeBox.add('group', undefined);
PaperSizegroup.orientation = 'row';
PaperSizegroup.alignment = [ScriptUI.Alignment.LEFT, ScriptUI.Alignment.TOP];
var PaperSizetxt = PaperSizegroup.add('statictext', undefined, "Paper Type : ");
PaperSizetxt.size = [105,20];
var PaperSize = PaperSizegroup.add ('edittext', [undefined, undefined, 200, 20], (PaperA3) );
PaperSize.active = false;

PresetBox = PrintBox.add ('panel', undefined, "Printer Preset");
PresetBoxgroup = PresetBox.add('group', undefined);
PresetBoxgroup.orientation = 'row';
PresetBoxgroup.alignment = [ScriptUI.Alignment.LEFT, ScriptUI.Alignment.TOP];
var Presettxt = PresetBoxgroup.add('statictext', undefined, "Printer Preset : ");
Presettxt.size = [105,20];
var Preset = PresetBoxgroup.add ('dropdownlist', [undefined, undefined, 200, 20], ["Paper" , "Film" , "Both", "Separation"] );
Preset.active = true;
Preset.selection = 0;

PrintBox.closebtn = PrintBox.add('button', undefined, "OK", {name:'OK'});

PrintBox.closebtn.onClick = function(){
box.close();
}

PrintBox.show();

var PresetText = Preset.selection.text;

switch (PresetText) {
case 'Paper':

var options = new PrintOptions();

var colorOptions = new PrintColorManagementOptions();
colorOptions.colorProfileMode = PrintColorProfile.PRINTERPROFILE;
colorOptions.intent = PrintColorIntent.RELATIVECOLORIMETRIC;
options.colorManagementOptions = colorOptions;

var sepOptions = new PrintColorSeparationOptions();
sepOptions.convertSpotColors = false;
sepOptions.overPrintBlack = true;
sepOptions.colorSeparationMode = PrintColorSeparationMode.COMPOSITE;
options.colorSeparationOptions = sepOptions;

var coordinateOptions = new PrintCoordinateOptions();
coordinateOptions.fitToPage = false;
coordinateOptions.position = PrintPosition.TRANSLATECENTER;
coordinateOptions.orientation = PrintOrientation.AUTOROTATE;
options.coordinateOptions = coordinateOptions;

var flatOpts = new PrintFlattenerOptions();
flatOpts.convertStrokesToOutlines = true;
flatOpts.convertTextToOutlines = true;
flatOpts.overprint = PDFOverprint.PRESERVEPDFOVERPRINT;
options.flattenerOptions = flatOpts;

var printJobOptions = new PrintJobOptions();
printJobOptions.designation = PrintArtworkDesignation.ALLLAYERS;
printJobOptions.reverse = false;
printJobOptions.printArea = PrintingBounds.ARTWORKBOUNDS;
printJobOptions.copies = 1;
printJobOptions.name = fileref;
printJobOptions.printAllArtboards = true;
options.jobOptions = printJobOptions;

var printPaperOpts = new PrintPaperOptions();
//printPaperOpts.name = PaperA3;
options.jobOptions = printJobOptions;
options.paperOptions = printPaperOpts;

options.printerName = PrintRicoh;
options.printPreset = "Print";

Doc.print(options); 

// function exportFileAsEPS(fileref) {
//     var EPSSaveOpts = new epsSaveOptions();
//     epsSaveOptions.cmykPostScript = true;
//     epsSaveOptions.embedAllFonts = true;
//     epsSaveOptions.embedLinkedFiles = true;
//     epsSaveOptions.includeDocumentThumbnails = true
//     epsSaveOptions.overprint = PDFOverprint.PRESERVEPDFOVERPRINT;
//     epsSaveOptions.postScript = EPSPostScriptLevelEnum.LEVEL2;
//     epsSaveOptions.preview = EPSPreview.COLORTIFF;
//     epsSaveOptions.saveMultipleArtboards = true;
//     Doc.saveAs (fileref,EPSSaveOpts);
// }
// Doc.saveAs (fileref,EPSSaveOpts);

break;

case 'Film':

var options = new PrintOptions();

var colorOptions = new PrintColorManagementOptions();
colorOptions.colorProfileMode = PrintColorProfile.PRINTERPROFILE;
colorOptions.intent = PrintColorIntent.RELATIVECOLORIMETRIC;
options.colorManagementOptions = colorOptions;

var sepOptions = new PrintColorSeparationOptions();
sepOptions.convertSpotColors = false;
sepOptions.overPrintBlack = true;
sepOptions.colorSeparationMode = PrintColorSeparationMode.COMPOSITE;
options.colorSeparationOptions = sepOptions;

var coordinateOptions = new PrintCoordinateOptions();
coordinateOptions.fitToPage = false;
coordinateOptions.position = PrintPosition.TRANSLATECENTER;
coordinateOptions.orientation = PrintOrientation.AUTOROTATE;
options.coordinateOptions = coordinateOptions;

var flatOpts = new PrintFlattenerOptions();
flatOpts.convertStrokesToOutlines = true;
flatOpts.convertTextToOutlines = true;
flatOpts.overprint = PDFOverprint.PRESERVEPDFOVERPRINT;
options.flattenerOptions = flatOpts;

var printJobOptions = new PrintJobOptions();
printJobOptions.designation = PrintArtworkDesignation.ALLLAYERS;
printJobOptions.reverse = false;
printJobOptions.printArea = PrintingBounds.ARTWORKBOUNDS;
printJobOptions.copies = 1;
printJobOptions.name = fileref;
printJobOptions.printAllArtboards = true;
options.jobOptions = printJobOptions;

var printPaperOpts = new PrintPaperOptions();
//printPaperOpts.name = PaperA3;
options.jobOptions = printJobOptions;
options.paperOptions = printPaperOpts;

options.printerName = PrintRicohFilm;
options.printPreset = "Film";

Doc.print(options);
//Doc.save ();

break;

case 'Both':

var options = new PrintOptions();
var printJobOptions = new PrintJobOptions();
options.jobOptions = printJobOptions;
options.printPreset = "Print";

Doc.print(options);

var options = new PrintOptions();
var printJobOptions = new PrintJobOptions();
options.jobOptions = printJobOptions;
options.printPreset = "Film";

Doc.print(options);
//Doc.save ();    

break;

case 'Separation' :

var options = new PrintOptions();

var printJobOptions = new PrintJobOptions();
printJobOptions.designation = PrintArtworkDesignation.ALLLAYERS;
printJobOptions.reverse = false;
printJobOptions.printArea = PrintingBounds.ARTWORKBOUNDS;
printJobOptions.copies = 1;
printJobOptions.name = fileref;
printJobOptions.printAllArtboards = true;
options.jobOptions = printJobOptions;

options.printPreset = "Separation";

Doc.print(options); 

// function exportFileAsEPS(fileref) {
//     var EPSSaveOpts = new epsSaveOptions();
//     epsSaveOptions.cmykPostScript = true;
//     epsSaveOptions.embedAllFonts = true;
//     epsSaveOptions.embedLinkedFiles = true;
//     epsSaveOptions.includeDocumentThumbnails = true
//     epsSaveOptions.overprint = PDFOverprint.PRESERVEPDFOVERPRINT;
//     epsSaveOptions.postScript = EPSPostScriptLevelEnum.LEVEL2;
//     epsSaveOptions.preview = EPSPreview.COLORTIFF;
//     epsSaveOptions.saveMultipleArtboards = true;
//}

break;

Doc.saveAs (fileref,EPSSaveOpts);

}