この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
前の記事でInDesignServerをインストールしたので、今回は起動した後接続してみます
SOAPを介してInDesignServerと通信するには、InDesignServerの起動時に-port引数を使用する必要があります
前回の記事でも行いましたが、
cd {InDesignServerのインストールフォルダ}; InDesignServer -port 18383
といった感じで起動すると、 [soap] ポート 18383 で SOAP 要求のサービス中
と出力されます
InDesign ServerのSOAPメソッド
InDesign ServerのSOAP実装には、RunScript、BeginSession、およびEndSessionの3つのメソッドが用意されています
各メソッドのパラメーターリスト、およびその結果の構造は、InDesignServerのWSDLによって定義されています。
RunScript
JavaScript、AppleScript、またはVBScriptで記述されたスクリプトをInDesign Serverに実行させ、結果を呼び出し元に返します。
BeginSession
セッションコンテキストでスクリプトを実行する場合は、RunScriptメソッドを呼び出す前にこれを呼び出します。
スクリプト実行のためにセッションを開き、セッションIDをクライアントに返すようにInDesignServerに通知します
EndSession
渡されたセッションIDに基づいて、スクリプト実行のために特定のセッションを閉じるようにInDesign Serverに通知します
RunScriptでサンプルのスクリプトを実行してみる
Adove.IOからダウンロードできるInDesign Server SDKに InDesignServerと対話するスクリプトおよびクライアント側アプリケーションを作成するためのライブラリとサンプルが含まれています。
今回はこのサンプルを使ってRunScriptから実行してみます。
スクリプトは、SDKのインストールフォルダの中の server\samples\scripts
フォルダ以下にあります。
登竜門であるHelloWorld系を使ってみます
サンプルのHelloWorld.jsx
//HelloWorld.jsx
//Create a new document.
var myDocument = app.documents.add();
//Get a reference to the first page.
var myPage = myDocument.pages.item(0);
//Create a text frame.
var myTextFrame = myPage.textFrames.add();
//Specify the size and shape of the text frame.
myTextFrame.geometricBounds = ["6p0", "6p0", "18p0", "18p0"];
//Enter text in the text frame.
myTextFrame.contents = "Hello World!";
//Save the document (fill in a valid file path).
var myFile = new File("/c/ServerTestFiles/HelloWorld.indd");
var result = "saved to: " + myFile.fullName;
if(!myFile.parent.exists && !myFile.parent.create()) {
result = "Not saved. Unable to create the folder: " + myFile.parent.fullName;
} else {
myDocument = myDocument.save(myFile);
}
//Close the document.
myDocument.close();
result;
このコードをInDesign Serverに実行してもらうようにクライアント側からSOAPでリクエストします。
クライアントを作成して実行
soapクライアントはjavascriptで作ってみました。
node-soapというライブラリを使用します。
const soap = require("soap")
const url = 'http://<<InDesign ServerのHost名/IP>>:18383/service?wsdl';
// RunScriptメソッドのパラメータ
const args = {
runScriptParameters:{
scriptFile: '<<Pass to SDK>>\\server\\samples\\scripts\\javascript\\HelloWorld.jsx',
scriptLanguage: 'javascript'
//scriptText: 'hello',
//'scriptArgs[]': [{arg0:1, arg1:"This is Text"}]
}
};
soap.createClient(url, function(err, client) {
client.setEndpoint(url);
client.Service.Service.RunScript(args, function(err, result, rawResponse, soapHeader, rawRequest) {
if(err) console.log(`err\n${err}`);
console.log(`result\n${JSON.stringify(result)}`);
})
});
上記コードを使って実行してみます。
RunScriptには
<complexType name="RunScriptParameters">
<sequence>
<element name="scriptText" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<element name="scriptLanguage" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<element name="scriptFile" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<element name="scriptArgs" type="IDSP:IDSP-ScriptArg" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
というのが定義されていて、これらをパラメーターとしてクライアントから渡しています。
実行するとこのように結果が返ってきます。
/c/ServerTestFiles/HelloWorld.indd というファイルがInDesign Serverのホストに生成されてるかどうか確認してみます。
HelloWorld.inddがありますね。
※ .inddはAdobe InDesignのファイルの拡張子です
最後に
InDesign ServerにSOAPで通信してSDKのサンプルスクリプトを実行しました。 今回はクライアントをjavascriptで書きましたが、SDKにもjava,aspnet,flexのサンプルクライアントが内包されていますので参考になると思います。
参考Doc
※ SDKの/docs/html/
にInDesign Server SDKの取り扱いや開発方法などについての詳しいドキュメントがあります