Is it possible to call a web service with Indesign javascript?
Asked Answered
B

5

18

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.

Borrowing answered 27/9, 2011 at 18:18 Comment(7)
Please leave constructive criticism as to how this is a bad question before simply downvoting it. I'm relatively new here and simply looking for help, trying to ask my questions as plainly as possible.Borrowing
... are you talking about calling a ws from a desktop publishing document?Calicut
Essentially, yes. I need to call a ws from within Adobe Indesign CS3 - CS5, though the plan doesn't require a document to be open yet when the script is called.Borrowing
Indesign? How does Indesign use javascript? And more importantly, why? I'm pretty sure printed brochures can't execute code.Orthodox
I believe you're right that a printed brochure can't execute code as of 2011. Indesign, however, is a computer program created by a company named Adobe. This program uses scripts to automate certain aspects of creating those documents while they're still on the computer. Automating this creation is helpful in cutting down on labor costs.Borrowing
Using State Machines: Web Access From Adobe InDesign CS3 ExtendScript rorohiko.blogspot.com/2008_07_01_archive.htmlHenryhenryetta
I'm curious if there's any modern solution to this now...Linsang
B
5

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.

Barranquilla answered 28/9, 2011 at 9:0 Comment(4)
I'm speechless. This Extendables library is brilliant. This is exactly what I needed. Thank you! I'd plus one multiple times if I could.Borrowing
@Ben, thanks for the tip on porky. Briefly looking at the codebase, I don't think porky was Extendables. They might share some common functionality, but they're structured differently and sometimes serve different purposes. porky looks to be a (web) DB connector for ExtendScript with some extras. Extendables is a test framework for ExtendScript with some extras.Sizzle
I don't think you can use jQuery for web requests in ExtendScript. Extendables makes use of sockets available to InDesign scripting engine. See github.com/debrouwere/Extendables/blob/master/core-packages/…. As for jQuery (internally) and browsers, they use XmlHttpRequest object, and that may not be exposed to ExtendScript unless ExtendScript supports calling ActiveX/COM objects or has an XmlHttpRequest object class.Sizzle
You may be right. I'm not sure exactly how well jQuery and other XmlHttpRequest-dependent libraries would work in the InDesign scripting engine. I would try it but I no longer have access to the needed tools, so I just edited the answer a bit.Barranquilla
V
6

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.

Vulgarity answered 14/10, 2011 at 14:41 Comment(2)
Extendables link is out of date.Nahshun
Seems like Extendables is dead? ...at least the link is!Linsang
B
5

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.

Barranquilla answered 28/9, 2011 at 9:0 Comment(4)
I'm speechless. This Extendables library is brilliant. This is exactly what I needed. Thank you! I'd plus one multiple times if I could.Borrowing
@Ben, thanks for the tip on porky. Briefly looking at the codebase, I don't think porky was Extendables. They might share some common functionality, but they're structured differently and sometimes serve different purposes. porky looks to be a (web) DB connector for ExtendScript with some extras. Extendables is a test framework for ExtendScript with some extras.Sizzle
I don't think you can use jQuery for web requests in ExtendScript. Extendables makes use of sockets available to InDesign scripting engine. See github.com/debrouwere/Extendables/blob/master/core-packages/…. As for jQuery (internally) and browsers, they use XmlHttpRequest object, and that may not be exposed to ExtendScript unless ExtendScript supports calling ActiveX/COM objects or has an XmlHttpRequest object class.Sizzle
You may be right. I'm not sure exactly how well jQuery and other XmlHttpRequest-dependent libraries would work in the InDesign scripting engine. I would try it but I no longer have access to the needed tools, so I just edited the answer a bit.Barranquilla
S
1

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?

Sizzle answered 24/4, 2015 at 22:9 Comment(3)
I've tried the scripts you mentioned, and they both work in the current versions of Bridge and InDesign, but they take 30 seconds or more to load a webpage that 367 bytes and loads in Safari in 30.7ms. Does that match up with your experience?Linsang
It's been several years since I last worked with the functionality, so unfortunately, I don't recall, but it was bearable to me. The Adobe products do take time to load up which can be a contributing factor to this. Sorry I couldn't be of more help.Sizzle
One might ponder if the slowness is specific to some versions of Bridge and InDesign, Illustrator, etc. Worse case scenario, you might want to look into the external scripting route with AppleScript or COM/VBScript to gain the speed advantage.Sizzle
W
1

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.

Whithersoever answered 27/4, 2015 at 9:17 Comment(0)
C
0

... 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.

Calicut answered 27/9, 2011 at 19:33 Comment(1)
JS? Then yes, you probably can, wonder if you could include the whole jQuery lib in the doc :-), make an Ajax call.Calicut

© 2022 - 2024 — McMap. All rights reserved.