Hieronder een voorbeeld van de code die momenteel werkt. Ik heb xml-bestand geëxporteerd van indesign. De tags en attributes van deze xml heb ik in een database opgeslagen. Met deze tags genereer ik een nieuwe xml met daarin de data die ik wil. Dit stuur ik met soap naar de indesignserver. De indesignserver gegeneerd nu een JPEG. Deze preview roep ik met ajax op zodat gebruikers een zo actueel mogelijk beeld hebben van wat ze maken.
Om het script te versnellen wil ik het aanmaken van het xml bestand overslaan. Ik wil de xml in een variabele opslaan en vervolgens meegeven aan de importXML functie. Met het stukje javascript dat ik meestuur kan ik de indesignserver aansturen (kan dus zijn dat de importXML functie alleen voor indesign scripting is):
"With InDesign scripting support, you can automate tedious production tasks such as placing and replacing images, correcting errors in text, and preparing files for printing. And it plays an integral role in XML and IDML-based workflows.."
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| public function generateXML($templateID, $tagValues) {
$xml = '';
$xml .= '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.EOL;
$xml .= '<Root>';
$tags = $this->getTagsFromTemplate($templateID);
if (is_array($tags)) {
$this->writeXML(&$xml, $tags, $tagValues);
}
$xml .= '</Root>';
$fp = fopen('path/test.xml', 'w');
fwrite($fp, $xml);
fclose($fp);
return $filename;
} |
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| $script = 'var myDocument = app.open (File("path/template.indt"), false);';
$script .= 'var myXMLImportPreferences = myDocument.xmlImportPreferences;';
$script .= 'with (myXMLImportPreferences) {';
$script .= ' allowTransform = false;';
$script .= ' createLinkToXML = false;';
$script .= ' ignoreUnmatchedIncoming = false;';
$script .= ' ignoreWhitespace = true;';
$script .= ' importCALSTables = true;';
$script .= ' importStyle = XMLImportStyles.mergeImport;';
$script .= ' importTextIntoTables = false;';
$script .= ' importToSelected = false;';
$script .= ' removeUnmatchedExisting = false;';
$script .= ' repeatTextElements = true;';
$script .= '}';
$script .= 'myDocument.xmlElements.item(0).importXML(File("path/test.xml"));';
$script .= 'app.jpegExportPreferences.resolution = 150;';
$script .= 'myDocument.exportFile(ExportFormat.jpg, new File("path/preview.jpg"));';
$script .= 'myDocument.close();';
$this->phpRunScript('path/IDSP.wsdl', 'http://host:port', '', $script, 'javascript', array(), true);
die('<img src="path/preview.jpg">'); |
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| private function phpRunScript($wsdl, $host, $scriptFile, $scriptText, $scriptLanguage, $scriptArgs, $printDebugInfo) {
try {
if ($host != '') {
$client = new SoapClient($wsdl, array('trace' => $printDebugInfo, 'encoding' => 'utf-8', 'location' => $host));
} else {
$client = new SoapClient($wsdl, array('trace' => $printDebugInfo, 'encoding' => 'utf-8'));
}
$runScriptParams = array ('runScriptParameters' => array('scriptText' => $scriptText, 'scriptLanguage' => $scriptLanguage, 'scriptFile' => $scriptFile, 'scriptArgs' => $scriptArgs, 'scriptcontent' => $scriptContent));
$result = $client->RunScript($runScriptParams);
unset($client);
} catch (SoapFault $exception) {
// ..blabla
}
} |