问题
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.
回答1:
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.
回答2:
Extendables was already mentioned:
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.
回答3:
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?
回答4:
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.
回答5:
... 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.
来源:https://stackoverflow.com/questions/7573831/is-it-possible-to-call-a-web-service-with-indesign-javascript