如何使用Adobe Indesign CS4中的Javascript打开文本文件?

时间:2009-08-30 03:36:42

标签: javascript adobe-indesign

如何打开文本文件,阅读内容,然后将内容插入InDesign中的文档?

4 个答案:

答案 0 :(得分:8)

以下是从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();

Here是指向File对象在线文档的链接。您还可以找到InDesign脚本DOM文档的其余部分here

答案 1 :(得分:4)

这是InDesign JavaScript脚本的pdf。在那里有一些File对象的提及,但它没有记录。 http://www.adobe.com/products/indesign/scripting/pdfs/InDesignCS4_ScriptingGuide_JS.pdf

这是因为这里记录了所有CS5产品的核心实用程序 https://www.adobe.com/content/dam/Adobe/en/devnet/indesign/cs55-docs/InDesignScripting/InDesign-ScriptingTutorial.pdf

或一般文件: http://www.adobe.com/content/dam/Adobe/en/devnet/scripting/pdfs/javascript_tools_guide.pdf

寻找:文件系统访问

答案 2 :(得分:0)

感谢指向各种PDF的指针 对此问题的回答位于execute()命令中。

    fileObj.execute()

答案 3 :(得分:-3)

出于安全原因,Javascript不允许访问您计算机的操作系统,文件或目录,因此无法使用Javascript直接访问文本文件。

通常使用服务器端技术(如PHP,Adobe Coldfusion,Java或.NET(例如))通过HTML表单提交上传文件,阅读并执行任何需要执行的操作。

我希望有所帮助。