如何打开文本文件,阅读内容,然后将内容插入InDesign中的文档?
以下是从InDesign中读取文件的示例.如果您也想写入文件,则需要open使用file写入模式w.
// Choose the file from a dialog
var file = File.openDialog();
// Or use a hard coded path to the file
// var file = File("~/Desktop/hello world.txt");
// Open the file for reading
file.open("r");
// Get the first text frame of the currently active document
var doc = app.activeDocument;
var firstTextframe = doc.pages[0].textFrames[0];
// Add the contents of the file to the text frame
firstTextframe.contents += file.read();
Run Code Online (Sandbox Code Playgroud)
这是File在线对象文档的链接.您还可以在此处找到InDesign脚本DOM文档的其余部分.
Cia*_*her -4
出于安全原因,Javascript 不允许访问您计算机的操作系统、文件或目录,因此无法直接使用 Javascript 访问文本文件。
通常,服务器端技术(例如 PHP、Adobe Coldfusion、Java 或 .NET)用于通过 HTML 表单提交上传文件、读取文件并执行所需的任何操作。
我希望这有帮助。