1

这对您的 Javascript/Extendscript 向导来说应该足够简单。我想使用打印预设打印文档,同时还指定页面范围(可能还有其他选项,在选择预设后)。查阅 InDesign CS6 JavaScript 脚本指南,它对如何做到这一点进行了精彩而详细的解释:

使用打印机预设打印

要使用打印机预设打印文档,请在打印命令中包含打印机预设。

哇。如此具有描述性和帮助。嗯,任何人都可以帮助我更好地理解这一点吗?


编辑(2019 年 1 月 21 日)

有人问我如何才能告诉脚本我想打印哪些页面。事实证明,这并没有存储在PrinterPreset.

Document有一个称为printPreferences允许访问PrintPreference对象的属性。此对象允许开发人员pageRange通过指定PageRange枚举或带有页面范围的字符串来设置 (“1”是第一页)。

所以,为了说明:

var document = app.activeDocument; // Presumes the document you want to print is already open.

document.printPreferences.pageRange = PageRange.ALL_PAGES; // Will print all pages in the document.
document.printPreferences.pageRange = "1-3,7,10,12-15" // Prints pages 1, 2, 3, 7, 10, 12, 13, 14, and 15.

注意: PageRange.SELECTED_ITEMS似乎只用于导出项目,而不是打印(因为PageRange枚举用于两种操作)。但是,我没有对此进行测试。

还有很多其他PrintPreference属性可以在document.print()被调用之前设置,所以值得一

4

1 回答 1

2

app.print()方法可以将PrinterPreset对象作为其参数之一。这是该方法参考的链接,以获取更多信息。

这是一个示例(未经测试):

var doc = app.activeDocument;

var file = File(doc.fullName);      // Get the active document's file object

var preset = app.printerPresets[0]; // Use your printer preset object

app.print(file, null, preset);

app.print()InDesign 参考或多或少地列出了这样的方法:

void print (from: varies[, printDialog: bool][, using: varies])
Prints the specified file(s).

Parameter    Type                Description
from         Array of Files      One or more file paths. Can accept: File or Array of Files.
             File
printDialog  bool                Whether to invoke the print dialog (Optional)
using        PrinterPreset       Printer preset to use. Can accept: PrinterPresetTypes enumerator or PrinterPreset. (Optional)
             PrinterPresetTypes

列出的第一个信息是方法的返回值void,在这种情况下,这意味着它不返回任何内容。

列出的下一个信息是方法的名称,print后跟它的命名参数:fromprintDialogusing以及每个参数类型应该是什么。

图表中还列出了参数以供进一步说明。例如,该from参数需要一个类型的对象FileFile因此,在上面的示例中,我通过调用它的构造函数来创建对象的“实例” : var file = File(doc.fullName);。然后我得到一个已经存在的PrinterPreset对象:var preset = app.printerPresets[0];. 最后,我将每个对象传递给插入null中间变量的函数(因为它是可选的,所以我决定忽略它)app.print(file, null, preset);

于 2013-05-21T13:20:01.100 回答