是否可以使用 Indesign javascript 调用 Web 服务?
我是一家印刷公司的内部开发人员。
我们使用 Adobe Indesign CS3 和 CS5 创建用于打印的文档。
我在 Adobe Extendscript 中创建了一个脚本,该脚本创建 Indesign 文档并在客户端无法自行处理时处理一些基本转换。
我使用 Javascript 来编写这个脚本。
是否可以通过这样的脚本调用Web服务?
如果是这样,怎么办?
如果没有,从桌面调用 Web 服务的最佳方式是什么?
谢谢。
I'm an in-house developer for a print company.
We use Adobe Indesign CS3 and CS5 to create documents for printing.
I created a script in Adobe Extendscript that creates an Indesign Document and handles some basic conversions when the client fails to do so themselves.
I used Javascript to write this script.
Is it possible to call a web service through such a script?
If so, how?
If not, what would be the best way to call a web service from the desktop?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
截至 2022 年,我会指向
已经提到了可扩展(不再存在):
Extendables
它不是 jQuery,而是 InDesign 脚本的库。
最完整的讨论可以在 Rorohiko 的博客 中找到,其中有一个很好的直接示例。
As of 2022 I would point to
Extendables was already mentioned (does not exist anymore):
Extendables
It is not jQuery, instead it is a library for InDesign Scripting.
The most complete discussion is found at Rorohiko's blog, with an nice straight forward example.
否和是。
不,(据我所知)没有办法让 InDesign 从脚本调用 Web 服务。这是很有可能的,并且经常通过 InDesign 插件完成(您可以执行任意 C++ 代码,因此您可以做任何事情)。然而,这是一个完全不同的学习野兽。
是的,可以使用库通过 ExtendScript 来完成。因此,基本上您的脚本将调用 Web 服务来获取数据(可能使用从 InDesign 或文档获取的参数),然后将返回的值发送到其他 InDesign 脚本函数中以执行操作。
可以在此处找到基本示例使用“可扩展”。
编辑:因为似乎存在一些混乱:这些文档不是运行脚本的文档,甚至很少包含它们。脚本以 InDesign 特定的 Javascript 格式 (.jsx) 保存,并由 InDesign 脚本引擎解释。
No and Yes.
No, there is no way (afaik) to make InDesign call a web service from a script. It's very possible and often done from InDesign plugins (you can execute arbitrary c++ code so you can do whatever). However, that's an entirely different beast to learn.
Yes, it's possible to do from ExtendScript using a library. So basically your script would call the web service to get data (maybe using parameters gotten from InDesign or the document) and then send the returned values into other InDesign script functions to perform the operations.
A basic sample can be found here that uses 'Extendables'.
EDIT: Since there seem to be some confusion: The documents aren't the ones running the script and very rarely even contain them. The scripts are saved in an InDesign specific Javascript format (.jsx) and interpreted by the InDesign scripting engine.
除了 Extendables 之外,还有 2 个替代选项:
Adobe Bridge/Bridgetalk
无法说明 Adobe 套件的特定版本,但如果您可以使用或拥有 Adobe Bridge/Bridgetalk,则可以使用 Adobe 的Bridge 可以使用跨应用程序通信和 HttpConnection 类(根据 SDK 文档),并让 InDesign 调用 Bridge 来发出 HTTP 请求并将结果传递回 InDesign。
我没有针对 InDesign 的具体示例,但这里有一些针对 Illustrator 的示例。我认为它可以轻松移植到 InDesign。
https://gist.github.com/daluu/2d9dec72d0863f9ff5a7
https://gist.github.com/mericson/6509997
从外部进行 Web 服务调用并与 ExtendScript 连接
Adobe 的脚本 API 引擎并非严格意义上的 ExtendScript/Javascript。您还可以使用来自 COM/VBScript(在 Windows 上)或 Applescript(在 Mac 上)的脚本 API,它们在 InDesign 外部执行,但通过 API 与 InDesign 交互。
对于 Windows,COM 是指任何支持 COM 的语言,因此它不仅仅是默认的 VBScript(可以是 Python、Perl、PHP、Java、.NET,甚至是 Microsoft JScript - 用于命令行/桌面/等的 Javascript 版本) .)。
在不同的引擎上使用脚本 API,您可以从其他语言(VBScript、Applescript 等)进行外部 Web 服务调用,然后通过应用程序的脚本 API 调用(在 COM/Applescript 中)将结果传递到 ExtendScript .doScript('ExtendScript code snippet here') (or doJavascript) 其中对于 ExtendScript 片段,可以是一个简短的片段,它使用 ExtendScript include 包含实际的 JSX 文件,然后调用 ExtendScript 函数/方法,将其传递给 Web 服务结果作为参数。
一些解决方案中描述了此技术的示例(不涵盖 Web 服务调用部分):
是否可以从外部 ExtendScript 执行 JSX 脚本?
Besides Extendables, there are 2 alternate options:
Adobe Bridge/Bridgetalk
Can't say for specific versions of the Adobe suite, but if you can use or have Adobe Bridge/Bridgetalk, you can make use of Adobe's cross app communication and HttpConnection class available to Bridge (as per the SDK doc), and have InDesign call Bridge to make the HTTP request and pass results back to InDesign.
I don't have specific example for InDesign, but here's some meant for Illustrator. I would assume it would port to InDesign easily.
https://gist.github.com/daluu/2d9dec72d0863f9ff5a7
https://gist.github.com/mericson/6509997
Make web service calls externally and interface to ExtendScript
Adobe's scripting API engine is not strictly ExtendScript/Javascript. You can also use the script API from COM/VBScript (on Windows) or Applescript (on Mac), which execute external to InDesign but interact with InDesign via the API.
For Windows, by COM, I mean any language that supports COM, so it's not just the default VBScript (can be Python, Perl, PHP, Java, .NET, even Microsoft JScript - their version of Javascript for command line/desktop/etc.).
Using the script API on a different engine, you make the web service call externally from other language (VBScript, Applescript, etc.) then pass the results into the ExtendScript via the script API call (in COM/Applescript) of application.doScript('ExtendScript code snippet here') (or doJavascript) where for ExtendScript snippet, could be a short snippet that uses ExtendScript includes to include actual JSX file then call a ExtendScript function/method, passing it the web service results as arguments.
An example of this technique (not covering the web service call portion) is described here in some of the solutions:
Is it possible to execute JSX scripts from outside ExtendScript?
您还可以根据操作系统调用 AppleScript 或 VB,并使用 cUrl 等命令行实用程序来调用您的 Web 服务。您还可以尝试 getUrl,这是 Rorohiko 提供的免费脚本,可简化 ExtendScript 内的 Web 通信。
You can also call AppleScript or VB depending on the os and use some command line utility like cUrl to call your webservice. Also you can give a try to getUrl, a free script from Rorohiko that eases web communication inside ExtendScript.
...可能如果您使用 InDesign 从文档创建 pdf。在 pdf 中你可能可以。但从原始 InDesign 文档来看可能不是。我还投票认为,在打开文档之前,您将无法从文档中运行 js。我建议与 InDesign 专家一起解决这个问题。不过我很好奇你会想到什么,因为我记得 ID 确实允许你在文档中包含交互性。如果您在其他地方找到答案,请回复。
... probably if you use InDesign to create a pdf out of the doc. In the pdf you probably can. But from the raw InDesign doc probably not. I'd also vote that you won't be able to run js from the document before it's open. I'd suggest taking it up with InDesign experts. I'm curious however what you'll come up with since I remember that ID does let you include interactivity in the document. Please post back if you find your answer somewhere else.