Search code examples
javascriptprintingadobe-indesignextendscript

Cannot set the printBlack printPreference in InDesign


I've learned an enormous amount of scripting for InDesign CS6 thanks to all of the helpful folks here! Now, it's a problem with setting the printPreferences for a document. Here is the code I have:

    with(document.printPreferences) {
        activePrinterPreset = outputPreset;
        pageRange = outputRange;
        for (var j = 0; j < allInks.length; j++) {
            document.inks.item(allInks[j]).printInk = false;
        }
        for (var k = 0; k < printInks.length; k++) {
            if (printInks[k].toString() === "Black") {
                $.writeln("Found Black!");
                printBlack = true;
                $.writeln("Set Black!");
            } else {
                document.inks.item(printInks[k]).printInk = true;
            }
        }
        if (offsetJob) {
            // If it's an offset job, we might need to change page sizes.
            if (productType === "HI-N13W") {
                paperSize = PaperSizes.custom;
                paperHeight = 12.5;
                paperWidth = 8.5;
            } else if (productType.subString(3,5) === "PC") {
                paperSize = PaperSizes.custom;
                paperHeight = 8;
                paperWidth = 12.5;
            } else if (couldBeBothJobs.toString().indexOf(productType.subString(3,5)) > -1) {
                paperSize = "US Letter";
            } else {
                paperSize = PaperSizes.custom;
                paperHeight = 8;
                paperWidth = 25;
            }
        }
    }

In the second for loop, you'll see that I have first turned off ALL of the inks in the document for printing. I then only turn on the ones in the printInks array. If, however, the word "Black" exists in the array, there isn't an Ink for it, so instead, I want to set the built-in printPreference "printBlack". (This complements the other three—printCyan, printMagenta, and printYellow.)

It's just supposed to be a boolean value, according to the InDesign CS6 Object Model Reference. However, whenever the script gets to that point, it halts. Pasting just that small bit of code to a fresh document, just so I can see the error message, gets me this:

    The property is not applicable in the current state.

What does this mean? And more importantly, how can I fix it? I know that trapping has to be off before this property can be set, but I've definitely made sure that it is off.


Solution

  • After asking this question on the Adobe Community Forums, I was told that some of the Print Preferences cannot be set directly on the document, but must instead be set on a Print Preset, which, in turn, is then set as the Active Print Preset. Thus, I just re-built the preset I needed and assigned it to a new, temporary one. The following is the result:

        try {
            tempPreset.name;
        }
        catch(eNoSuchPreset) {
            tempPreset = app.printerPresets.add({name:"tempPreset"});
        }
    
        // Let's turn off all of the spot colors before everything else.
        for (var j = 0; j < allInks.length; j++) {
            document.inks.item(allInks[j]).printInk = false;
        }
    
            with(document.printPreferences) {
                tempPreset.printer = Printer.POSTSCRIPT_FILE;
                tempPreset.ppd = "OYO Imagesetter";
                tempPreset.pagePosition = PagePositions.CENTERED;
                tempPreset.paperSize = PaperSizes.CUSTOM;
                tempPreset.paperHeight = "12.5 in";
                tempPreset.paperWidth = "6.5 in";
                tempPreset.colorOutput = ColorOutputModes.SEPARATIONS;
                tempPreset.trapping = Trapping.OFF;
                tempPreset.screening = "60 lpi / 600 dpi";
                tempPreset.sendImageData = ImageDataTypes.OPTIMIZED_SUBSAMPLING;
                pageRange = outputRange;
                // Now let's turn off all of the CMYK colors.
                tempPreset.printCyan = false;
                tempPreset.printMagenta = false;
                tempPreset.printYellow = false;
                tempPreset.printBlack = false;
                // Then we turn back on BLACK if it exists.
                for (var k = 0; k < printInks.length; k++) {
                    if (printInks[k] === "Black") {
                        tempPreset.printBlack = true;
                    } else {
                        document.inks.item(printInks[k]).printInk = true;
                    }
                }
                // If this is a four-color process job, then turn back on all of the process colors.
                if (processJob) {
                    tempPreset.printCyan = true;
                    tempPreset.printMagenta = true;
                    tempPreset.printYellow = true;
                    tempPreset.printBlack = true;
                }
                // That concludes OYO seps.
            }
            var mydpp = document.printPreferences;
            mydpp.activePrinterPreset = "tempPreset";
    

    That gets my 99% of the way to completing this script. YAY!!