├── LICENSE
├── README.md
├── generate-idml-rnc
└── generate-idml-rnc.jsx
├── image-export
├── README.md
├── delete-image-labels.jsx
├── image-export.jsx
└── image-export_pre-cs6.jsx
├── indb
└── ExportChapterAsIDML.jsx
├── insert-alt-text
├── README.md
└── insert-alt-text.jsx
├── line-numbers
├── README.md
└── line-numbers.jsx
├── link-endnotes
├── README.md
└── link-endnotes.jsx
├── pagenames
├── PageNamesToStoryALL.jsx
├── PageNamesToStory_ConditionalText.jsx
├── PageNamesToStory_Notes.jsx
├── PageNamesToStory_Notes_Book.jsx
└── README.md
├── paragraph-textDestinations
├── README.md
└── insertTextDestinations.jsx
├── text-to-image
├── README.md
└── ReplaceSelectedTextAsImage.jsx
└── transpect-preflight
└── transpect-preflight.jsx
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014–2024, le-tex publishing services GmbH
2 |
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without
6 | modification, are permitted provided that the following conditions are met:
7 |
8 | * Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | * Redistributions in binary form must reproduce the above copyright notice,
12 | this list of conditions and the following disclaimer in the documentation
13 | and/or other materials provided with the distribution.
14 |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 |
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | InDesignScripts
2 | ===============
3 |
4 | Collection of InDesign scripts for inserting page numbers as conditional text, exporting .indb to multiple .idml + catalog, etc.
5 |
--------------------------------------------------------------------------------
/generate-idml-rnc/generate-idml-rnc.jsx:
--------------------------------------------------------------------------------
1 | #targetengine "session"
2 |
3 | var version = "v1.0.0";
4 | /*
5 | * set language
6 | */
7 | var lang = {
8 | pre: app.locale == 1279477613 ? 1 : 0 // en = 0, de = 1
9 | }
10 | /*
11 | * options object
12 | */
13 | options = {
14 | schemaDir:"export",
15 | exportPackageSchema:true
16 | }
17 | /*
18 | * set panel preferences
19 | */
20 | panel = {
21 | title:["le-tex – Generate IDML schema", "le-tex – IDML-Schema erzeugen"][lang.pre],
22 | selectDirMenuTitle:["Save schema as", "Schema speichern unter"][lang.pre],
23 | selectDirButtonTitle:["Choose", "Auswählen"][lang.pre],
24 | chooseSchema:["Choose schema", "Schema auswählen"][lang.pre],
25 | optionsTitle:["Choose schema-type", "Schema-Typ auswählen"][lang.pre],
26 | exportPackageSchemaValues:[["Package", "File"], ["Paket", "Datei"]][lang.pre],
27 | buttonOK:"OK",
28 | buttonCancel:["Cancel", "Abbrechen"][lang.pre],
29 | finishedMessage:["Schema exported!", "Schema exportiert!"][lang.pre]
30 | }
31 | /*
32 | * start
33 | */
34 | main();
35 | /*
36 | * main pipeline
37 | */
38 | function main(){
39 | var userLevel = app.scriptPreferences.userInteractionLevel;
40 | app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
41 | // open file dialog and load a document
42 | if (app.layoutWindows.length == 0) {
43 | var file = File.openDialog ("Select a file", "InDesign:*.indd;*.indb;*.idml, InDesign Document:*.indd, InDesign Book:*.indb, InDesign Markup:*.idml", true)
44 | try {
45 | app.open(File(file));
46 | } catch (e) {
47 | alert(e);
48 | return;
49 | };
50 | }
51 | var doc = app.documents[0];
52 | // check if document is saved
53 | if ((!doc.saved || doc.modified)) {
54 | if ( confirm ("The document needs to be saved.", undefined, "Document not saved.")) {
55 | try {
56 | doc = doc.save();
57 | } catch (e) {
58 | alert ("The document couldn't be saved.\n" + e);
59 | return;
60 | }
61 | } else {
62 | return;
63 | }
64 | }
65 | try{
66 | drawWindow(doc) == 1
67 | } catch(e){
68 | alert(e);
69 | }
70 | }
71 | /*
72 | * User Interface
73 | */
74 | function drawWindow(doc) {
75 | var myWindow = new Window("palette", panel.title + " " + version, undefined);
76 | myWindow.orientation = "column";
77 | myWindow.alignChildren ="fill";
78 | var panelSelectDir = myWindow.add("panel", undefined, panel.selectDirMenuTitle);
79 | panelSelectDir.alignChildren = "left";
80 | var panelSelectDirPath = panelSelectDir.add("edittext");
81 | panelSelectDirPath.preferredSize.width = 255;
82 | panelSelectDirPath.text = getDefaultExportPath();
83 | var panelSelectDirButtonGroup = panelSelectDir.add("group");
84 | panelSelectDirButtonGroup.alignChildren = "left";
85 | var panelSelectDirButton = panelSelectDirButtonGroup.add("button", undefined, panel.selectDirButtonTitle);
86 | // dropdown
87 | var panelOptions = myWindow.add("panel", undefined, panel.optionsTitle);
88 | var panelOptionsDropdown = panelOptions.add("dropdownlist", undefined, panel.exportPackageSchemaValues);
89 | panelOptionsDropdown.selection = 0;
90 | // buttons OK/Cancel
91 | panelOptions.alignChildren = "left";
92 | var panelButtonGroup = myWindow.add("group");
93 | panelButtonGroup.orientation = "row";
94 | var buttonOK = panelButtonGroup.add("button", undefined, panel.buttonOK, {name: "ok"});
95 | var buttonCancel = panelButtonGroup.add("button", undefined, panel.buttonCancel, {name: "cancel"} );
96 | // change text to selected file path
97 | panelSelectDirButton.onClick = function() {
98 | panelSelectDirPath.text = "hirz"
99 | var result = Folder.selectDialog ();
100 | if (result) {
101 | panelSelectDirPath.text = result;
102 | }
103 | }
104 | buttonOK.onClick = function (){
105 | //overwrite values with form input
106 | options.schemaDir = Folder(panelSelectDirPath.text);
107 | options.exportPackageSchema = (panelOptionsDropdown.selection.index == 0) ? true : false;
108 | myWindow.close(1);
109 | generateRNCSchema();
110 | }
111 | buttonCancel.onClick = function() {
112 | myWindow.close();
113 | }
114 | return myWindow.show();
115 | }
116 | function generateRNCSchema(){
117 | app.generateIDMLSchema(Folder(options.schemaDir), options.exportPackageSchema);
118 | alert(panel.finishedMessage);
119 | }
120 | // get path relative to indesign file location
121 | function getDefaultExportPath() {
122 | var exportPath = String(app.activeDocument.fullName);
123 | exportPath = exportPath.substring(0, exportPath.lastIndexOf('/')) + '/' + options.schemaDir;
124 | return exportPath
125 | }
126 |
--------------------------------------------------------------------------------
/image-export/README.md:
--------------------------------------------------------------------------------
1 | # image-export.jsx
2 |
3 | A script for Adobe InDesign to export images to web-friendly formats.
4 |
5 | ## Installation
6 |
7 | 1. open InDesign Scripts panel
8 | 2. right-click on folder entitled "User" and select "Reveal in Explorer/Finder"
9 | 3. copy image-export.jsx to this folder
10 |
11 | ## Requirements
12 |
13 | * image-export.jsx needs at least Adobe InDesign Version 8.0 (CS6)
14 | * image-export_pre-cs6.jsx works with Adobe InDesign Version 7.0 (CS5) but supports only JPG output. I've tested it on CS5 but it may work on CS4 as well.
15 |
16 | ## Features
17 |
18 | * adjusted size, bleed, transparency and orientation settings are applied and automatically exported (please note that this works not with locked layers)
19 | * for multiple linked images, every instance is stored as separate image with a unique name and its settings
20 | * select output directory, compression ratio, density and choose between JPG and PNG format
21 | * support InDesign object export options
22 | * set resolution limit
23 |
24 | ## Limitations
25 |
26 | * Embedded images are not exported. Consider to convert embedded images to linked images instead.
27 |
28 | ## IDML
29 |
30 | * for multiple instances of one image, each instance is exported with a unique filename
31 | * the new filename is stored in the IDML as ``Label`` of the ``Rectangle`` element
32 |
33 | ```xml
34 |
35 |
36 |
39 |
40 |
41 |
42 | ```
43 |
--------------------------------------------------------------------------------
/image-export/delete-image-labels.jsx:
--------------------------------------------------------------------------------
1 | options = {
2 | labelNames:['letex:fileName', 'letex:altText', 'px:bildFileName', 'px:Foot2EndnoteHyperlink']
3 | }
4 |
5 | main();
6 |
7 | function main(){
8 | // open file dialog and load a document
9 | if (app.layoutWindows.length == 0) {
10 | var file = File.openDialog ("Select a file", "InDesign:*.indd;*.indb;*.idml, InDesign Document:*.indd, InDesign Book:*.indb, InDesign Markup:*.idml", true)
11 | try {
12 | app.open(File(file));
13 | } catch (e) {
14 | alert(e);
15 | return;
16 | };
17 | }
18 | var doc = app.documents[0];
19 | // check if document is saved
20 | if ((!doc.saved || doc.modified)) {
21 | if ( confirm ("The document needs to be saved.", undefined, "Document not saved.")) {
22 | try {
23 | var userLevel = app.scriptPreferences.userInteractionLevel;
24 | app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
25 | doc = doc.save();
26 | app.scriptPreferences.userInteractionLevel = userLevel;
27 | } catch (e) {
28 | alert ("The document couldn't be saved.\n" + e);
29 | return;
30 | }
31 | }
32 | else {
33 | return;
34 | }
35 | }
36 | // show window
37 | try {
38 | deleteLabel(doc);
39 | } catch (e) {
40 | alert ("Error:\n" + e);
41 | }
42 | }
43 | function deleteLabel(doc){
44 | var allPageItems = doc.allPageItems;
45 | for (var i = 0; i < allPageItems.length; i++) {
46 | var obj = doc.allPageItems[i];
47 | if(obj.constructor.name == 'Group' || obj.constructor.name == 'Rectangle'){
48 | for (var j = 0; j < options.labelNames.length; ++j) {
49 | obj.insertLabel(options.labelNames[j], '');
50 | }
51 | }
52 | }
53 | alert('OK');
54 | }
55 |
--------------------------------------------------------------------------------
/image-export/image-export_pre-cs6.jsx:
--------------------------------------------------------------------------------
1 | /*
2 | * image-export.jsx
3 | *
4 | *
5 | * Export images from an InDesign document to web-friendly formats.
6 | *
7 | *
8 | * Note: this script works with InDesign version 5.0 and above. Previous
9 | * versions may compatible, too but not tested yet.
10 | *
11 | *
12 | * Authors: Gregor Fellenz (twitter: @grefel), Martin Kraetke (@mkraetke)
13 | *
14 | *
15 | * LICENSE
16 | *
17 | * Copyright (c) 2015, Gregor Fellenz and le-tex publishing services GmbH
18 | * All rights reserved.
19 | *
20 | * Redistribution and use in source and binary forms, with or without
21 | * modification, are permitted provided that the following conditions are met:
22 | *
23 | * 1. Redistributions of source code must retain the above copyright notice,
24 | * this list of conditions and the following disclaimer.
25 | *
26 | * 2. Redistributions in binary form must reproduce the above copyright notice,
27 | * this list of conditions and the following disclaimer in the documentation
28 | * and/or other materials provided with the distribution.
29 | *
30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
31 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
33 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
34 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
35 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
36 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
37 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 | * POSSIBILITY OF SUCH DAMAGE.
40 | *
41 | */
42 |
43 | /*
44 | * set image export preferences
45 | */
46 |
47 | lang = {
48 | pre: 0 // en = 0, de = 1
49 | }
50 |
51 | image = {
52 | minExportDPI:1,
53 | maxExportDPI:2400,
54 | exportDPI:144,
55 | maxResolution:4000000,
56 | exportDir:"export",
57 | exportQuality:2,
58 | pageItemLabel:"letex:fileName"
59 | }
60 | /*
61 | * set panel preferences
62 | */
63 | panel = {
64 | title:["le-tex – Export Images", "le-tex – Bilder exportieren"][lang.pre],
65 | densityTitle:["Density (ppi)", "Auflösung (ppi)"][lang.pre],
66 | qualityTitle:["Quality", "Qualität"][lang.pre],
67 | qualityValues:[["max", "high", "medium", "low"], ["Maximum", "Hoch", "Mittel", "Niedrig"]][lang.pre],
68 | optionsTitle:["Options", "Optionen"][lang.pre],
69 | maxResolutionTitle:["Max Resolution (px)", "Maximale Auflösung (px)"][lang.pre],
70 | selectDirButtonTitle:["Choose", "Auswählen"][lang.pre],
71 | selectDirMenuTitle:["Choose a directory", "Verzeichnis auswählen"][lang.pre],
72 | progressBarTitle:["export Images", "Bilder exportieren"][lang.pre],
73 | noValidLinks:["No valid links found.", "Keine Bild-Verknüpfungen gefunden"][lang.pre],
74 | finishedMessage:["images exported.", "Bilder exportiert."][lang.pre],
75 | buttonOK:"OK",
76 | buttonCancel:["Cancel", "Abbrechen"][lang.pre],
77 | errorMissingImage:["Warning! Image cannot be found: ", "Warnung! Bild konnte nicht gefunden werden: "][lang.pre],
78 | errorEmbeddedImage:["Warning! Embedded Image cannot be exported: ", "Warnung! Eingebettetes Bild kann nicht exportiert werden: "][lang.pre],
79 | promptMissingImages:["Some images cannot be exported. Proceed?","Einige Bilder können nicht exportiert werden. Fortfahren?"][lang.pre]
80 | }
81 |
82 | /*
83 | * start
84 | */
85 | main();
86 |
87 | function main(){
88 | // open file dialog and load a document
89 | if (app.layoutWindows.length == 0) {
90 | var file = File.openDialog ("Select a file", "InDesign:*.indd;*.indb;*.idml, InDesign Document:*.indd, InDesign Book:*.indb, InDesign Markup:*.idml", true)
91 | try {
92 | app.open(File(file));
93 | } catch (e) {
94 | alert(e);
95 | return;
96 | };
97 | }
98 | var doc = app.documents[0];
99 | // check if document is saved
100 | if ((!doc.saved || doc.modified)) {
101 | if ( confirm ("The document needs to be saved.", undefined, "Document not saved.")) {
102 | try {
103 | var userLevel = app.scriptPreferences.userInteractionLevel;
104 | app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
105 | doc = doc.save();
106 | app.scriptPreferences.userInteractionLevel = userLevel;
107 | } catch (e) {
108 | alert ("The document couldn't be saved.\n" + e);
109 | return;
110 | }
111 | }
112 | else {
113 | return;
114 | }
115 | }
116 | // show window
117 | try {
118 | jsExtensions();
119 | exportImages(doc);
120 | } catch (e) {
121 | alert ("Error:\n" + e);
122 | }
123 | }
124 |
125 | function jsExtensions(){
126 | // indexOf
127 | if (!Array.prototype.indexOf)
128 | {
129 | Array.prototype.indexOf = function(elt /*, from*/)
130 | {
131 | var len = this.length;
132 |
133 | var from = Number(arguments[1]) || 0;
134 | from = (from < 0)
135 | ? Math.ceil(from)
136 | : Math.floor(from);
137 |
138 | if (from < 0)
139 | from += len;
140 |
141 | for (; from < len; from++)
142 | {
143 | if (from in this &&
144 | this[from] === elt)
145 | return from;
146 | }
147 | return -1;
148 | };
149 | }
150 | }
151 |
152 | function exportImages(doc){
153 | if(drawWindow() == 1){
154 | // overwrite internal Measurement Units to pixels
155 | app.scriptPreferences.measurementUnit = MeasurementUnits.PIXELS;
156 | // grab file links and export
157 | getFilelinks(doc);
158 | } else {
159 | return;
160 | }
161 | }
162 |
163 | function drawWindow(){
164 | var myWindow = new Window("dialog", panel.title, undefined, {resizable:true});
165 | with (myWindow) {
166 | myWindow.orientation = "column";
167 | myWindow.alignChildren ="fill";
168 | myWindow.formPath = add("panel", undefined, panel.selectDirMenuTitle);
169 | with(myWindow.formPath){
170 | myWindow.formPath.alignChildren = "left";
171 | myWindow.formPath.inputPath = add("edittext");
172 | myWindow.formPath.inputPath.preferredSize.width = 255;
173 | myWindow.formPath.inputPath.text = getDefaultExportPath();
174 | myWindow.formPath.buttonChoosePath = add("button", undefined, panel.selectDirButtonTitle);
175 | }
176 | myWindow.qualityGroup = add("panel", undefined, panel.qualityTitle);
177 | with(myWindow.qualityGroup){
178 | qualityGroup.orientation = "column";
179 | qualityGroup.alignChildren = "left";
180 | qualityGroup.formQuality = add("group");
181 | with(myWindow.qualityGroup.formQuality){
182 | formQuality.orientation = "row";
183 | for (i = 0; i < panel.qualityValues.length; i++) {
184 | formQuality.add ("radiobutton", undefined, (panel.qualityValues[i]));
185 | }
186 | formQuality.children[image.exportQuality].value =true;
187 | }
188 | myWindow.qualityGroup.formDensity = add( "group");
189 | with(myWindow.qualityGroup.formDensity){
190 | formDensity.inputDPI = add ("edittext", undefined, image.exportDPI);
191 | formDensity.inputDPI.characters = 4;
192 | formDensity.sliderDPI = add("slider", undefined, image.exportDPI, image.minExportDPI, image.maxExportDPI);
193 | formDensity.add ("statictext", undefined, panel.densityTitle);
194 | // synchronize slider and input field
195 | formDensity.sliderDPI.onChanging = function () {myWindow.qualityGroup.formDensity.inputDPI.text = myWindow.qualityGroup.formDensity.sliderDPI.value};
196 | formDensity.inputDPI.onChanging = function () {myWindow.qualityGroup.formDensity.sliderDPI.value = myWindow.qualityGroup.formDensity.inputDPI.text};
197 | }
198 | }
199 | myWindow.optionsGroup = add("panel", undefined, panel.optionsTitle);
200 | with(myWindow.optionsGroup){
201 | myWindow.optionsGroup.maxResolutionGroup = add("group");
202 | with(myWindow.optionsGroup.maxResolutionGroup){
203 | maxResolutionGroup.inputMaxRes = maxResolutionGroup.add("edittext", undefined, image.maxResolution);
204 | maxResolutionGroup.add("statictext", undefined, panel.maxResolutionTitle);
205 | }
206 | }
207 | myWindow.buttonGroup = add( "group");
208 | with(myWindow.buttonGroup){
209 | myWindow.buttonGroup.orientation = "row";
210 | myWindow.buttonGroup.buttonOK = add ("button", undefined, panel.buttonOK, {name: "ok"});
211 | myWindow.buttonGroup.buttonCancel = add ("button", undefined, panel.buttonCancel, {name: "cancel"} );
212 | }
213 | }
214 | myWindow.formPath.buttonChoosePath.onClick = function () {
215 | var result = Folder.selectDialog ();
216 | if (result) {
217 | myWindow.formPath.inputPath.text = result;
218 |
219 | }
220 | }
221 | myWindow.buttonGroup.buttonOK.onClick = function(){
222 | //overwrite values with form input
223 | image.exportDir = Folder(myWindow.formPath.inputPath.text);
224 | image.exportDPI = Number(myWindow.qualityGroup.formDensity.inputDPI.text);
225 | image.exportQuality = selectedRadiobutton(myWindow.qualityGroup.formQuality);
226 | image.maxResolution = Number(myWindow.optionsGroup.maxResolutionGroup.inputMaxRes.text);
227 | myWindow.close(1);
228 |
229 | function selectedRadiobutton (rbuttons){
230 | for(var i = 0; i < rbuttons.children.length; i++) {
231 | if(rbuttons.children[i].value == true) {
232 | return i;
233 | }
234 | }
235 | }
236 | }
237 | myWindow.buttonGroup.buttonCancel.onClick = function() {
238 | myWindow.close();
239 | }
240 | return myWindow.show();
241 | }
242 |
243 |
244 | function getFilelinks(doc){
245 |
246 | var docLinks = doc.links;
247 | var uniqueBasenames = [];
248 | var exportLinks = []
249 | /*
250 | * rename files if a basename exists twice
251 | */
252 | for (var i = 0; i < docLinks.length; i++) {
253 | var link = docLinks[i];
254 |
255 | if(isValidLink(link)){
256 |
257 | var originalBounds = link.parent.parent.geometricBounds;
258 | var rectangle = link.parent.parent;
259 | // disable lock since this prevents images to be exported
260 | // note that just the group itself has a lock state, not their childs
261 |
262 | if(rectangle.parent.constructor.name == 'Group'){
263 | if(rectangle.parent.locked != false){
264 | rectangle.parent.locked = false;
265 | }
266 | }else{
267 | if(rectangle.locked != false){
268 | rectangle.locked = false;
269 | }
270 | }
271 | var normalizedDensity = getMaxDensity(image.exportDPI, rectangle, image.maxResolution);
272 |
273 | var basename = getBasename(link.name);
274 | // use existing filename label
275 | if(rectangle.extractLabel(image.pageItemLabel).length > 0){
276 | var newFilename = rectangle.extractLabel(image.pageItemLabel);
277 | // generate new filename if basename exists twice
278 | }else if(inArray(basename, uniqueBasenames)) {
279 | var newFilename = renameFile(basename, "jpg", true);
280 | } else {
281 | uniqueBasenames.push(basename);
282 | var newFilename = renameFile(basename, "jpg", false);
283 | }
284 |
285 | /*
286 | * construct link object
287 | */
288 | linkObject = {
289 | link:link,
290 | pageItem:rectangle,
291 | quality:image.exportQuality,
292 | density:normalizedDensity,
293 | newFilename:newFilename,
294 | newFilepath:File(image.exportDir + "/" + newFilename),
295 | originalBounds:originalBounds
296 | }
297 |
298 | /*
299 | * check for custom object export options
300 | */
301 | exportLinks.push(linkObject);
302 |
303 | } else {
304 |
305 | var missingLinks = true;
306 | }
307 |
308 | }
309 |
310 | if (missingLinks) {
311 | var result = confirm ("Missing Image Links found. Proceed?");
312 | if (!result) return;
313 | }
314 | // create directory
315 | createDir(image.exportDir);
316 |
317 | if (exportLinks.length > 0) {
318 | //var progressBar = getProgressBar(exportLinks.length);
319 | var progressBar = getProgressBar("export " + exportLinks.length + " images");
320 | progressBar.reset(exportLinks.length);
321 |
322 |
323 | // iterate over files and store to specific location
324 | for (i = 0; i < exportLinks.length; i++) {
325 | var exportFormat = ExportFormat.JPG;
326 | var exportResolution = exportLinks[i].density;
327 | var exportQuality = exportLinks[i].quality;
328 | // JPEG export options
329 | app.jpegExportPreferences.antiAlias = false;
330 | app.jpegExportPreferences.embedColorProfile = false;
331 | app.jpegExportPreferences.exportResolution = exportResolution;
332 | app.jpegExportPreferences.jpegColorSpace = JpegColorSpaceEnum.RGB;
333 | jpegExportQualityValues = [JPEGOptionsQuality.MAXIMUM ,JPEGOptionsQuality.HIGH, JPEGOptionsQuality.MEDIUM, JPEGOptionsQuality.LOW];
334 | app.jpegExportPreferences.jpegQuality = jpegExportQualityValues[exportQuality];
335 | app.jpegExportPreferences.jpegRenderingStyle = JPEGOptionsFormat.BASELINE_ENCODING;
336 | app.jpegExportPreferences.simulateOverprint = true;
337 | app.jpegExportPreferences.useDocumentBleeds = true;
338 |
339 | progressBar.hit("export " + exportLinks[i].newFilename, i);
340 |
341 | exportLinks[i].pageItem.exportFile(exportFormat, exportLinks[i].newFilepath);
342 | // insert label with new file link for postprocessing
343 | exportLinks[i].pageItem.insertLabel(image.pageItemLabel, exportLinks[i].newFilename);
344 | // restore original bounds
345 | exportLinks[i].pageItem.geometricBounds = exportLinks[i].originalBounds;
346 | }
347 | progressBar.close();
348 |
349 | alert (exportLinks.length + " " + panel.finishedMessage);
350 | doc.save();
351 | }
352 | else {
353 | alert (panel.noValidLinks);
354 | }
355 | }
356 | // draw simple progress bar
357 | function getProgressBar (title){
358 | var progressBarWindow = new Window("palette", title, {x:0, y:0, width:400, height:50});
359 | var pbar = progressBarWindow.add("progressbar", {x:10, y:10, width:380, height:6}, 0, 100);
360 | var stext = progressBarWindow.add("statictext", {x:10, y:26, width:380, height:20}, '');
361 | progressBarWindow.center();
362 | progressBarWindow.reset = function (maxValue) {
363 | stext.text = "export export export export export export export export ";
364 | pbar.value = 0;
365 | pbar.maxvalue = maxValue||0;
366 | pbar.visible = !!maxValue;
367 | this.show();
368 | }
369 | progressBarWindow.hit = function(msg, value) {
370 | ++pbar.value;
371 | stext.text = msg;
372 | }
373 | return progressBarWindow;
374 | }
375 | // create directory
376 | function createDir (folder) {
377 | try {
378 | folder.create();
379 | return;
380 | } catch (e) {
381 | alert (e);
382 | }
383 | }
384 | // check if image is missing or embedded
385 | function isValidLink (link) {
386 | if(link.parent.parent.parentPage == null) {
387 | return false;
388 | } else {
389 | switch (link.status) {
390 | case LinkStatus.LINK_MISSING:
391 | alert(panel.errorMissingImage + link.name); return false; break;
392 | case LinkStatus.LINK_EMBEDDED:
393 | alert(panel.errorEmbeddedImage + link.name); return false; break;
394 | default:
395 | if(link != null) return true else return false;
396 | }
397 | }
398 | }
399 |
400 | // return filename with new extension and conditionally attach random string
401 | function renameFile(basename, extension, rename) {
402 | if(rename) {
403 | hash = ((1 + Math.random())*0x1000).toString(36).slice(1, 6);
404 | var renameFile = basename + '-' + hash + '.' + extension.toLowerCase();
405 | return renameFile
406 | } else {
407 | var renameFile = basename + '.' + extension.toLowerCase();
408 | return renameFile
409 | }
410 | }
411 | // get file basename
412 | function getBasename(filename) {
413 | var basename = filename.match( /^(.*?)\.[a-z]{2,4}$/i);
414 | if(basename != null){
415 | return basename[1];
416 | }else{
417 | // no file extension
418 | return filename;
419 | }
420 | }
421 | // check if string exists in array
422 | function inArray(string, array) {
423 | var length = array.length;
424 | for(var i = 0; i < length; i++) {
425 | if(array[i] == string)
426 | return true;
427 | }
428 | return false;
429 | }
430 |
431 | // get density limit according to maximal resolution value
432 | function getMaxDensity(density, rectangle, maxResolution) {
433 | var bounds = rectangle.geometricBounds;
434 | var baseMultiplier = 72;
435 | var densityFactor = density / baseMultiplier;
436 | var width = (bounds[3] - bounds[1]);
437 | var height = (bounds[2] - bounds[0]);
438 | var resolution = width * height * Math.pow(densityFactor, 2);
439 | if(resolution > maxResolution) {
440 | var maxDensity = Math.floor(Math.sqrt(maxResolution * Math.pow(densityFactor, 2) / resolution) * baseMultiplier);
441 | return maxDensity;
442 | } else {
443 | return density;
444 | }
445 | }
446 |
447 | // get path relative to indesign file location
448 | function getDefaultExportPath() {
449 | var exportPath = String(app.activeDocument.fullName);
450 | exportPath = exportPath.substring(0, exportPath.lastIndexOf('/')) + '/' + image.exportDir;
451 | return exportPath
452 | }
453 |
--------------------------------------------------------------------------------
/indb/ExportChapterAsIDML.jsx:
--------------------------------------------------------------------------------
1 | /*
2 | * ExportChapterAsIDML.jsx
3 | *
4 | *
5 | * Exports selected chapters from an INDB file to IDML and creates a result XML file.
6 | *
7 | *
8 | * Note: this script requires at least InDesign Version 6.0 (CS4).
9 | *
10 | * Authors: Matthias Quiering, Martin Kraetke (@mkraetke)
11 | *
12 | * Parts of this script originate from the work of Peter Kahrel.
13 | */
14 | #target indesign;
15 |
16 | version = "v1.0.3";
17 |
18 | lang = {
19 | pre: app.locale == 1279477613 ? 1 : 0 // en = 0, de = 1
20 | }
21 | panel = {
22 | title:["le-tex – Export INDB as IDML", "le-tex – INDB als IDML exportieren"][lang.pre],
23 | selectDirTitle:["Select output directory", "Speicherort auswählen"][lang.pre],
24 | buttonDirSelect:["Select", "Auswählen"][lang.pre],
25 | selectChaptersTitle:["Select book parts", "Buchteile auswählen"][lang.pre],
26 | buttonSelectAll:["Select all", "Alle markieren"][lang.pre],
27 | buttonDeselect:["Deselect all", "Auswahl aufheben"][lang.pre],
28 | buttonInvertSelection:["Invert selection", "Auswahl umkehren"][lang.pre],
29 | buttonOk:"OK",
30 | buttonCancel:["Cancel", "Abbrechen"][lang.pre],
31 | exportMsg:["Exporting...", "Exportiere..."][lang.pre],
32 | versionErrorMsg:["InDesign versions prior to CS4 are not supported.", "InDesign-Versionen vor CS4 werden nicht unterstützt."][lang.pre],
33 | finishedMsg:["Finished!", "Fertig!"][lang.pre],
34 | selectBookTitle:["Select INDB file", "INDB-Datei auswählen"][lang.pre],
35 | selectBookErrorMsg:["No INDB file selected", "Keine INDB-Datei geöffnet"][lang.pre]
36 | }
37 | values = {
38 | outputDir:null,
39 | selectedChapters:null
40 | }
41 | // Nur ausführbar, ab CS4 aufwärts
42 | var myVersion = app.scriptPreferences.version;
43 | if(Number(myVersion.slice(0, myVersion.indexOf("."))) > 5) {
44 | export_to_idml (app.books.item (get_book ()));
45 | } else {
46 | alert(panel.versionErrorMsg)
47 | }
48 | function export_to_idml (book) {
49 | var win = draw_window(book);
50 | var myDefaultInteraction = app.scriptPreferences.userInteractionLevel;
51 | app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
52 | chapters_to_idml (book, values.selectedChapters.chapters, values.outputDir);
53 | app.scriptPreferences.userInteractionLevel = myDefaultInteraction;
54 | }
55 | function chapters_to_idml (thisbook, chapters, dir) {
56 | var myFolder = Folder(dir);
57 | if(myFolder != null){
58 | var myFolderName = myFolder.fsName; // Windows-spezifische Namenskonvention ( /f/TEMP/ ==> F:\TEMP )
59 | var myDefaultViewPDF = app.pdfExportPreferences.viewPDF;
60 | var f;
61 | var myDocList = "\r";
62 | var myFolderPath = "";
63 | if (myFolder.fullName.match(/^\/\w\//g)) myFolderPath = "/" + myFolder.fullName.substr(1, 1) + ":" + myFolder.fullName.slice(2,); // A) Netzlaufwerk (z.B. "/i/indesign")
64 | else if (myFolder.fullName.match(/^~/g)) myFolderPath = "/" + myFolder.fsName.replace(/\\/g, "/"); // B) Nutzerverzeichnis (z.B. "~/Desktop/...")
65 | else myFolderPath = myFolder.fullName; // C) Serverpfad (z.B. "//Rennratte/indesign/...")
66 | myFolderPath = myFolderPath.replace(/[%&,; \(\)]/g, '_');
67 | myDocList += "\r";
68 | var p_list = progress_list (create_list (chapters), panel.exportMsg);
69 | for (var i = 0; i < chapters.length; i++){
70 | try{
71 | p_list[i].text = '+';
72 | var myDoc = app.open (chapters[i], false);
73 | var firstPage = myDoc.pages.firstItem().name;
74 | var lastPage = myDoc.pages.lastItem().name;
75 | var pageCount = myDoc.pages.length;
76 | f = new File (myFolderName + "\\" + chapters[i].name.replace(/indd$/, 'idml'));
77 | myDoc.exportFile(ExportFormat.INDESIGN_MARKUP, f, false);
78 | myDoc.close(SaveOptions.NO);
79 | myDocList += " \r";
84 | } catch(e) {
85 | alert(e);
86 | }
87 | }
88 | p_list[0].parent.parent.close ();
89 | myDocList += "";
90 | myTargetFile = new File(myFolderName + "\\" + thisbook.name.replace(/\.indb$/, '') + ".indb.xml");
91 | myTargetFile.encoding = "UTF-8";
92 | myTargetFile.open('w');
93 | myTargetFile.write(myDocList);
94 | myTargetFile.close();
95 | alert(panel.finishedMsg);
96 | }
97 | }
98 | function first_page (doc){
99 | return String (doc.pages[0].name)
100 | }
101 | function create_list (f){
102 | var array = [];
103 | for (i = 0; i < f.length; i++)
104 | array.push (f[i].name);
105 | return array
106 | }
107 | // draw window
108 | function draw_window (book){
109 | var array = [];
110 | var book_contents = book.bookContents.everyItem().fullName;
111 | for (var i = 0; i < book_contents.length; i++)
112 | array[i] = File (book_contents[i]).name;
113 | var w = new Window ("dialog", panel.title + " " + version + " | " + book.name);
114 | w.orientation = "column";
115 | w.alignChildren = ["fill", "fill"];
116 | var panelSelectDir = w.add("panel", undefined, panel.selectDirTitle);
117 | panelSelectDir.orientation = ["row"];
118 | panelSelectDir.alignChildren = ["left", "top"];
119 | var panelSelectDirInputPath = panelSelectDir.add("edittext");
120 | panelSelectDirInputPath.preferredSize.width = 255;
121 | panelSelectDirInputPath.text = Folder(book.filePath);
122 | var panelSelectDirButton = panelSelectDir.add("button", undefined, panel.buttonDirSelect);
123 | var panelChooseChapters = w.add("panel", undefined, panel.selectChaptersTitle);
124 | panelChooseChapters.alignChildren = ["left", "top"];
125 | panelChooseChapters.orientation = "row";
126 | var g1 = panelChooseChapters.add("group");
127 | g1.alignChildren = "fill";
128 | g1.orientation = "column";
129 | var list = g1.add ('listbox', undefined, array, {multiselect: true});
130 | list.maximumSize.height = 700;
131 | list.minimumSize.width = 250;
132 | var buttons = panelChooseChapters.add ('group');
133 | buttons.orientation = 'column';
134 | var select_all = buttons.add ('button', undefined, panel.buttonSelectAll);
135 | var deselect_all = buttons.add ('button', undefined, panel.buttonDeselect);
136 | var invert = buttons.add ('button', undefined, panel.buttonInvertSelection);
137 | var buttonOkCancel = w.add("group");
138 | buttonOkCancel.orientation = "row"
139 | buttonOkCancel.childrenAlign = "right"
140 | var ok = buttonOkCancel.add ('button', undefined, panel.buttonOk, {name: 'ok'});
141 | var cancel = buttonOkCancel.add ('button', undefined, panel.buttonCancel, {name:'cancel'});
142 | panelSelectDirButton.preferredSize = select_all.preferredSize = deselect_all.preferredSize = invert.preferredSize
143 | = ok.preferredSize = cancel.preferredSize = [120,20];
144 | panelSelectDirButton.onClick = function(){
145 | var result = Folder.selectDialog ();
146 | if (result) {
147 | panelSelectDirInputPath.text = result;
148 | }
149 | }
150 | select_all.onClick = function (){
151 | var all_items = new Array();
152 | var L = list.items.length;
153 | for (var i = 0; i < L; i++)
154 | all_items[i] = list.items[i];
155 | list.selection = all_items;
156 | }
157 | // select all items on start-up
158 | select_all.notify();
159 | invert.onClick = function (){
160 | var selected_items = new Array();
161 | var L = list.items.length;
162 | for (var i = 0; i < L; i++)
163 | if (list.items[i].selected == false)
164 | selected_items.push (list.items[i]);
165 | list.selection = null;
166 | list.selection = selected_items;
167 | }
168 | deselect_all.onClick = function (){
169 | list.selection = null;
170 | }
171 | if(w.show () == 1){
172 | var selected_docs = get_selected (list, book_contents);
173 | values.outputDir = panelSelectDirInputPath.text;
174 | values.selectedChapters = {chapters: selected_docs};
175 | w.close ();
176 | } else {
177 | w.close ();
178 | exit();
179 | }
180 | }
181 | function get_selected (selected_list, booklist){
182 | var array = [];
183 | for (var i = 0; i < selected_list.items.length; i++)
184 | if (selected_list.items[i].selected)
185 | array.push (booklist[selected_list.items[i].index]);
186 | return array
187 | }
188 | function array_pos (item, array){
189 | for (var i = 0; i < array.length; i++)
190 | if (item == array[i])
191 | return i;
192 | return 0
193 | }
194 | function read_history (s){
195 | var temp = "";
196 | var f = File (script_dir() + s);
197 | if (f.exists){
198 | f.open ('r');
199 | var temp = f.read ();
200 | f.close ();
201 | }
202 | return temp
203 | }
204 | function store_history (s, picked){
205 | var f = File (script_dir() + s);
206 | f.open ('w');
207 | f.write (picked);
208 | f.close ()
209 | }
210 | function progress_bar (stop, title){
211 | w___ = new Window ('palette', title);
212 | pb___ = w___.add ('progressbar', undefined, 0, stop);
213 | pb___.preferredSize = [300,20];
214 | w___.show()
215 | return pb___;
216 | }
217 | function progress_list (array, title){
218 | var txt = [];
219 | dlg___ = new Window ('palette', title);
220 | dlg___.orientation = 'row';
221 | var gr1 = dlg___.add ('group');
222 | gr1.orientation = 'column';
223 | gr1.alignChildren = ['left','top'];
224 | for (var i = 0; i < array.length; i++){
225 | txt[i] = gr1.add ('statictext', undefined, '');
226 | txt[i].characters = 1
227 | }
228 | var gr2 = dlg___.add ('group');
229 | gr2.minimumSize.width = 200;
230 | gr2.orientation = 'column';
231 | gr2.alignChildren = ['left','top'];
232 | for (var i = 0; i < array.length; i++)
233 | gr2.add ('statictext', undefined, array[i]);
234 | dlg___.show();
235 | return txt;
236 | }
237 | function script_dir(){
238 | try {return File (app.activeScript).path + '/'}
239 | catch (e) {return File (e.fileName).path + '/'}
240 | }
241 | function errorM (m){
242 | alert (m, 'Error', true);
243 | exit();
244 | }
245 | function get_book (){
246 | switch (app.books.length) {
247 | case 0: alert(panel.selectBookErrorMsg); exit();
248 | case 1: return app.books[0].name;
249 | default: return pick_book();
250 | }
251 | }
252 | function pick_book (){
253 | var w = new Window ("dialog", panel.selectBookTitle);
254 | w.alignChildren = "right";
255 | var g = w.add ("group");
256 | var list = g.add ("listbox", undefined, app.books.everyItem().name);
257 | list.minimumSize.width = 250;
258 | list.selection = 0;
259 | var b = w.add ("group");
260 | b.add ("button", undefined, panel.buttonOK, {name: "ok"})
261 | b.add ("button", undefined, panel.buttonCancel, {name: "cancel"})
262 | if (w.show () == 1)
263 | return list.selection.text;
264 | else
265 | exit ();
266 | }
267 |
--------------------------------------------------------------------------------
/insert-alt-text/README.md:
--------------------------------------------------------------------------------
1 | # insert-alt-text.jsx
2 |
3 | A script for Adobe InDesign to insert alt texts from an XML source.
4 |
5 | ## Requirements
6 |
7 | You need an XML file with this structure. You can use the script as well to create a blank template including the links in the InDesign document:
8 |
9 | ```xml
10 |
11 |
12 |
13 |
14 |
15 | ```
16 |
17 | ## Description
18 |
19 | For each XML link element whose file reference matches an InDesign link reference, the alt text is
20 | inserted into the Object Export Options of the rectangle.
21 |
22 | ```xml
23 |
24 |
25 |
26 |
27 |
28 | ```
29 |
30 | Additionally, a `letex:alt-text` label is inserted:
31 |
32 | ```xml
33 |
34 |
35 |
38 |
39 |
40 |
41 | ```
42 |
--------------------------------------------------------------------------------
/insert-alt-text/insert-alt-text.jsx:
--------------------------------------------------------------------------------
1 | #targetengine "session"
2 | /*
3 | * insert-alt-text.jsx
4 | *
5 | *
6 | * Insert alt text from an XML document
7 | *
8 | *
9 | * Authors: Martin Kraetke (@mkraetke)
10 | *
11 | */
12 | jsExtensions();
13 | var version = "v1.3.0";
14 | /*
15 | * set language
16 | */
17 | var lang = {
18 | pre: app.locale == 1279477613 ? 1 : 0 // en = 0, de = 1
19 | }
20 | /*
21 | * options object
22 | */
23 | options = {
24 | exportDir:"export",
25 | altTextXml:"alt-text.xml",
26 | altLabel:"letex:altText",
27 | artifactLabel:"letex:artifact",
28 | filenameLabel:"letex:fileName",
29 | logFilename:"alt-text.log",
30 | overrideExistingAltTexts:true,
31 | ignoreFileExtension:false,
32 | treatGroupAsSingleImage:false
33 | }
34 | /*
35 | * set panel preferences
36 | */
37 | panel = {
38 | title:["le-tex – Insert Alt Text", "le-tex – Alternativtexte einfügen"][lang.pre],
39 | selectDirButtonTitle:["Choose", "Auswählen"][lang.pre],
40 | generateAltXMLTitle:["Create XML file", "XML-Datei erstellen"][lang.pre],
41 | selectDirMenuTitle:["Choose XML file with alt texts", "XML-Datei mit Alternativtexten auswählen"][lang.pre],
42 | selectDirOpenFileDialogTitle:["Open XML file with alt texts", "XML-Datei mit Alternativtexten öffnen"][lang.pre],
43 | optionsTitle:["Options", "Optionen"][lang.pre],
44 | overrideExistingAltTextsTitle:["Override alt texts?", "Alt-Texte überschreiben"][lang.pre],
45 | ignoreFileExtensionTitle:["IgnoreFileExtension", "Dateiendung ignorieren"][lang.pre],
46 | treatGroupAsSingleImageTitle:["Image group as single image", "Bildgruppe als Einzelbild behandeln"][lang.pre],
47 | buttonOK:"OK",
48 | buttonCancel:["Cancel", "Abbrechen"][lang.pre],
49 | lockedLayerWarning:["All layers with images must be unlocked.","Alle Ebenen mit Bildern müssen entsperrt sein."][lang.pre],
50 | xmlNotFound:["No XML file found", "Keine XML-Datei gefunden!"][lang.pre],
51 | lockedLayerWarning:["All layers with images must be unlocked.","Alle Ebenen mit Bildern müssen entsperrt sein."][lang.pre],
52 | generateAltXMLFinishedMsg:["Empty alt text XML file created", "Leere Alt-Text-XML-Datei erstellt"][lang.pre],
53 | finishedMessage:["Alt texts inserted", "Alt-Texte eingefügt!"][lang.pre]
54 | }
55 | /*
56 | * start
57 | */
58 | main();
59 | /*
60 | * main pipeline
61 | */
62 | function main(){
63 | var userLevel = app.scriptPreferences.userInteractionLevel;
64 | app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
65 | // open file dialog and load a document
66 | if (app.layoutWindows.length == 0) {
67 | var file = File.openDialog ("Select a file", "InDesign:*.indd;*.indb;*.idml, InDesign Document:*.indd, InDesign Book:*.indb, InDesign Markup:*.idml", true)
68 | try {
69 | app.open(File(file));
70 | } catch (e) {
71 | alert(e);
72 | return;
73 | };
74 | }
75 | var doc = app.documents[0];
76 | // check if document is saved
77 | if ((!doc.saved || doc.modified)) {
78 | if ( confirm ("The document needs to be saved.", undefined, "Document not saved.")) {
79 | try {
80 | doc = doc.save();
81 | } catch (e) {
82 | alert ("The document couldn't be saved.\n" + e);
83 | return;
84 | }
85 | } else {
86 | return;
87 | }
88 | }
89 | // show window
90 | try {
91 | initializeWindow(doc);
92 | } catch (e) {
93 | alert ("Error:\n" + e);
94 | }
95 | app.scriptPreferences.userInteractionLevel = userLevel;
96 | }
97 | /*
98 | * add JavaScript extensions
99 | */
100 | function jsExtensions(){
101 | // indexOf
102 | if (!Array.prototype.indexOf) {
103 | Array.prototype.indexOf = function(elt /*, from*/)
104 | {
105 | var len = this.length;
106 |
107 | var from = Number(arguments[1]) || 0;
108 | from = (from < 0)
109 | ? Math.ceil(from)
110 | : Math.floor(from);
111 |
112 | if (from < 0)
113 | from += len;
114 |
115 | for (; from < len; from++) {
116 | if (from in this &&
117 | this[from] === elt)
118 | return from;
119 | }
120 | return -1;
121 | };
122 | }
123 | // endsWith
124 | String.prototype.endsWith = function(suffix) {
125 | return this.indexOf(suffix, this.length - suffix.length) !== -1;
126 | };
127 | }
128 | function initializeWindow(doc){
129 | try{
130 | drawWindow(doc) == 1
131 | } catch(e){
132 | alert(e);
133 | }
134 | }
135 | /*
136 | * User Interface
137 | */
138 | function drawWindow(doc) {
139 | //var myWindow = new Window("dialog", panel.title + " " + version, undefined, {resizable:true});
140 | var myWindow = new Window("palette", panel.title + " " + version, undefined);
141 | myWindow.orientation = "column";
142 | myWindow.alignChildren ="fill";
143 | var panelSelectDir = myWindow.add("panel", undefined, panel.selectDirMenuTitle);
144 | panelSelectDir.alignChildren = "left";
145 | var panelSelectDirInputPath = panelSelectDir.add("edittext");
146 | panelSelectDirInputPath.preferredSize.width = 255;
147 | panelSelectDirInputPath.text = getDefaultExportPath();
148 | var panelSelectDirButtonGroup = panelSelectDir.add("group");
149 | panelSelectDirButtonGroup.alignChildren = "left";
150 | var panelSelectDirButton = panelSelectDirButtonGroup.add("button", undefined, panel.selectDirButtonTitle);
151 | var generateAltXMLButton = panelSelectDirButtonGroup.add("button", undefined, panel.generateAltXMLTitle);
152 | // buttons OK/Cancel
153 | var panelOptions = myWindow.add("panel", undefined, panel.optionsTitle);
154 | panelOptions.alignChildren = "left";
155 | var overrideExistingAltTexts = panelOptions.add("checkbox", undefined, panel.overrideExistingAltTextsTitle);
156 | overrideExistingAltTexts.value = options.overrideExistingAltTexts;
157 | var ignoreFileExtension = panelOptions.add("checkbox", undefined, panel.ignoreFileExtensionTitle);
158 | ignoreFileExtension.value = options.ignoreFileExtension;
159 | var treatGroupAsSingleImage = panelOptions.add("checkbox", undefined, panel.treatGroupAsSingleImageTitle);
160 | treatGroupAsSingleImage.value = options.treatGroupAsSingleImage;
161 | var panelButtonGroup = myWindow.add("group");
162 | panelButtonGroup.orientation = "row";
163 | var buttonOK = panelButtonGroup.add("button", undefined, panel.buttonOK, {name: "ok"});
164 | var buttonCancel = panelButtonGroup.add("button", undefined, panel.buttonCancel, {name: "cancel"} );
165 | // change text to selected file path
166 | panelSelectDirButton.onClick = function() {
167 | var result = Folder(panelSelectDirInputPath.text).openDlg(panel.selectDirOpenFileDialogTitle, "XML:*.xml", true);
168 | if (result) {
169 | panelSelectDirInputPath.text = result;
170 | }
171 | }
172 | generateAltXMLButton.onClick = function() {
173 | options.altTextXml = File(panelSelectDirInputPath.text + "/alt-text.xml");
174 | options.treatGroupAsSingleImage = treatGroupAsSingleImage.value;
175 | myWindow.close(1);
176 | generateAltXML(doc);
177 | }
178 | buttonOK.onClick = function (){
179 | //overwrite values with form input
180 | options.exportDir = Folder(getDefaultExportPath() + '/' + options.exportDir);
181 | options.altTextXml = File(panelSelectDirInputPath.text);
182 | options.overrideExistingAltTexts = overrideExistingAltTexts.value;
183 | options.ignoreFileExtension = ignoreFileExtension.value;
184 | options.treatGroupAsSingleImage = treatGroupAsSingleImage.value;
185 | myWindow.close(1);
186 | prepareAltTexts(doc);
187 | }
188 | buttonCancel.onClick = function() {
189 | myWindow.close();
190 | }
191 | return myWindow.show();
192 | }
193 | function prepareAltTexts(doc) {
194 | var xmlExtension = String(options.altTextXml).split(".").pop().toLowerCase()
195 | if(xmlExtension == 'xml' && File(options.altTextXml).exists){
196 | // clear log
197 | clearLog(options.exportDir, options.logFilename);
198 | var currentDate = new Date();
199 | var dateTime = currentDate.getDate() + '/'
200 | + (currentDate.getMonth()+1) + '/'
201 | + currentDate.getFullYear() + ' '
202 | + currentDate.getHours() + ':'
203 | + currentDate.getMinutes() + ':'
204 | + currentDate.getSeconds();
205 | writeLog("le-tex insert-alt-text " + version + "\nstarted at " + dateTime + "\n", options.exportDir, options.logFilename);
206 | // open XML file
207 | var xmlFile = File(options.altTextXml);
208 | xmlFile.open("r");
209 | var xml = XML(xmlFile.read());
210 | // iterate over file links
211 | var docLinks = doc.links;
212 | var altLinks = [];
213 | var penalty = 0;
214 | for (var i = 0; i < docLinks.length; i++) {
215 | var link = docLinks[i];
216 | writeLog("(" + i + ") --------------------------------------------------------------------------------\n"
217 | + link.name
218 | + "\n"
219 | + link.filePath, options.exportDir, options.logFilename);
220 | var rectangle = link.parent.parent;
221 | var filename = link.name;
222 | var toBeExported = true;
223 | if(rectangle.parent.constructor.name == "Group" && options.treatGroupAsSingleImage){
224 | rectangle = getTopmostGroup(rectangle);
225 | filename = getLinkNameForGroup(rectangle);
226 | if(filename != link.name) {
227 | toBeExported = false;
228 | penalty++;
229 | }
230 | }
231 | var basename = filename.split('.').slice(0, -1).join('.')
232 | var filenameLabel = rectangle.extractLabel(options.filenameLabel);
233 | var xpath;
234 | if(String(filenameLabel).length > 0) {
235 | xpath = '/links/link[@name = \'' + filename + '\' or @name = \'' + filenameLabel + '\']';
236 | } else if(options.ignoreFileExtension) {
237 | xpath = '/links/link[starts-with(@name, \'' + basename + '\')]';
238 | } else {
239 | xpath = '/links/link[@name = \'' + filename + '\']';
240 | }
241 | writeLog('XPath: ' + xpath, options.exportDir, options.logFilename);
242 | var altText = String(xml.xpath(xpath + '/@alt'));
243 | var artifact = String(xml.xpath(xpath + '/@artifact'));
244 | if (altText.length != 0 && toBeExported) {
245 | writeLog('alt: ' + altText, options.exportDir, options.logFilename);
246 | altLinkObject = {
247 | rectangle:rectangle,
248 | filename:filename,
249 | altText:altText
250 | }
251 | altLinks.push(altLinkObject);
252 | } else if (artifact == 'true' && toBeExported) {
253 | writeLog('artifact: ' + artifact, options.exportDir, options.logFilename);
254 | altLinkObject = {
255 | rectangle:rectangle,
256 | filename:filename,
257 | altText:"",
258 | artifact:"true"
259 | }
260 | altLinks.push(altLinkObject);
261 | } else if (!toBeExported) {
262 | writeLog('INFO: part of group that is already processed!', options.exportDir, options.logFilename);
263 | } else {
264 | writeLog('WARNING: no alt text found!', options.exportDir, options.logFilename);
265 | }
266 | }
267 | var counter = insertAltTexts(altLinks, penalty);
268 | alert (counter + " " + panel.finishedMessage);
269 | writeLog("\n===============================================================================================\nFinished! Inserted alt links for " + altLinks.length + " of " + docLinks.length + " images.\nPlease check messages above for further details.", options.exportDir, options.logFilename);
270 | xmlFile.close();
271 | doc.save();
272 | } else {
273 | alert(panel.xmlNotFound);
274 | }
275 | }
276 | function insertAltTexts(altLinks, penalty){
277 | var counter = 0 - penalty;
278 | for (i = 0; i < altLinks.length; i++) {
279 | if(options.overrideExistingAltTexts == true || String(altLinks[i].rectangle.objectExportOptions.customAltText).length == 0) {
280 | altLinks[i].rectangle.insertLabel(options.altLabel, altLinks[i].altText);
281 | altLinks[i].rectangle.objectExportOptions.altTextSourceType = SourceType.SOURCE_CUSTOM;
282 | altLinks[i].rectangle.objectExportOptions.customAltText = altLinks[i].altText;
283 | counter++;
284 | } else {
285 | altLinks[i].rectangle.insertLabel(options.altLabel, altLinks[i].rectangle.objectExportOptions.customAltText);
286 | writeLog('WARNING: alt text found but not overriden!', options.exportDir, options.logFilename);
287 | }
288 | if(altLinks[i].artifact == "true") {
289 | altLinks[i].rectangle.insertLabel(options.altLabel, "");
290 | altLinks[i].rectangle.insertLabel(options.artifactLabel, altLinks[i].artifact);
291 | altLinks[i].rectangle.objectExportOptions.applyTagType = TagType.TAG_ARTIFACT;
292 | }
293 | }
294 | return counter;
295 | }
296 | function generateAltXML(doc){
297 | var myAltXML = "\r\r";
298 | var docLinks = doc.links;
299 | for (var i = 0; i < docLinks.length; i++) {
300 | var link = docLinks[i];
301 | var rectangle = link.parent.parent;
302 | var filename = link.name;
303 | if(rectangle.parent.constructor.name == "Group" && options.treatGroupAsSingleImage){
304 | rectangle = getTopmostGroup(rectangle);
305 | filename = getLinkNameForGroup(rectangle);
306 | }
307 | var filenameLabel = rectangle.extractLabel(options.filenameLabel);
308 | var nameAtt = filenameLabel.length > 0 ? filenameLabel : filename;
309 | var altAtt = String(rectangle.objectExportOptions.customAltText).length > 0 ? rectangle.objectExportOptions.customAltText : "";
310 | var isArtifact = rectangle.objectExportOptions.applyTagType == TagType.TAG_ARTIFACT;
311 | if((!options.treatGroupAsSingleImage || filename == link.name)){
312 | myAltXML += " \r";
318 | }
319 | }
320 | myAltXML += ""
321 | myTargetFile = new File(options.altTextXml);
322 | myTargetFile.encoding = "UTF-8";
323 | myTargetFile.open('w');
324 | myTargetFile.write(myAltXML);
325 | myTargetFile.close();
326 | alert(panel.generateAltXMLFinishedMsg + ": " + options.altTextXml + ".");
327 | }
328 | // get path relative to indesign file location
329 | function getDefaultExportPath() {
330 | var exportPath = String(app.activeDocument.fullName);
331 | exportPath = exportPath.substring(0, exportPath.lastIndexOf('/')) + '/';
332 | return exportPath
333 | }
334 | function createDir (folder) {
335 | try {
336 | folder.create();
337 | return;
338 | } catch (e) {
339 | alert (e);
340 | }
341 | }
342 | // simple logging
343 | function writeLog(message, dir, filename){
344 | var path = dir + '/' + filename;
345 | createDir(dir);
346 | var write_file = File(path);
347 | if (!write_file.exists) {
348 | write_file = new File(path);
349 | }
350 | d = new Date();
351 | var timestr = "[" + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + "] "
352 | write_file.open('a', undefined, undefined);
353 | write_file.encoding = "UTF-8";
354 | write_file.lineFeed = "Unix";
355 | write_file.writeln(timestr + message);
356 | write_file.close();
357 | }
358 | function clearLog(dir, filename){
359 | var path = dir + '/' + filename;
360 | del_file = File(path);
361 | if (del_file.exists) {
362 | del_file.remove();
363 | }
364 | }
365 | function getTopmostGroup(rectangle){
366 | var p = rectangle.parent;
367 | while(p.parent.constructor.name == "Group"){
368 | p = p.parent;
369 | }
370 | return p;
371 | }
372 | function getLinkNameForGroup(group) {
373 | var graphics = group.allGraphics;
374 | var link;
375 | for (var i = 0; i < graphics.length; i++) {
376 | if (graphics[i].isValid) {
377 | link = graphics[i].itemLink.name;
378 | }
379 | }
380 | return link;
381 | }
--------------------------------------------------------------------------------
/line-numbers/README.md:
--------------------------------------------------------------------------------
1 | # line-numbers.jsx
2 |
3 | A script for Adobe InDesign to automatically insert line numbers.
4 |
5 | ## Installation
6 |
7 | * open InDesign Scripts panel
8 | * right-click on folder entitled "User" and select "Reveal in Explorer/Finder"
9 | * copy image-export.jsx to this folder
10 |
11 | ## Requirements
12 |
13 | * works with Adobe InDesign Version 8.0 (CS6) and later
14 | * not yet tested with earlier versions
15 |
16 | ## Features
17 |
18 | * insert line numbers for certain paragraphs, text frames, stories or the entire document
19 | * optional ignore empty lines
20 | * continue or restart numbering on page breaks or new text frames
21 | * creates object and paragraph styles which can be customized later
22 |
--------------------------------------------------------------------------------
/line-numbers/line-numbers.jsx:
--------------------------------------------------------------------------------
1 | /*
2 | * line-numbers.jsx
3 | *
4 | *
5 | * This script adds line numbers to text frames.
6 | *
7 | * Author: Martin Kraetke (Twitter: @mkraetke)
8 | *
9 | *
10 | * LICENSE
11 | *
12 | * Copyright (c) 2015, le-tex publishing services GmbH
13 | * All rights reserved.
14 | *
15 | * Redistribution and use in source and binary forms, with or without
16 | * modification, are permitted provided that the following conditions are met:
17 | *
18 | * 1. Redistributions of source code must retain the above copyright notice,
19 | * this list of conditions and the following disclaimer.
20 | *
21 | * 2. Redistributions in binary form must reproduce the above copyright notice,
22 | * this list of conditions and the following disclaimer in the documentation
23 | * and/or other materials provided with the distribution.
24 | *
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
31 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 | * POSSIBILITY OF SUCH DAMAGE.
35 | *
36 | */
37 | //@targetengine "session"
38 |
39 | options = {
40 | debug:1,
41 | styles:[],
42 | restartNumPage:1,
43 | restartNumFrame:1,
44 | ignoreEmptyLines:1,
45 | applyToStyle:0,
46 | applyTo:0,
47 | interval:1,
48 | intervalFirstLine:0,
49 | startFrom:1,
50 | counter:0,
51 | pageOffset: app.documents[0].pages[0].documentOffset, // start with 1st page
52 | lineNumberObjStyleName: "Obj_LineNumber",
53 | lineNumberParaStyleName: "Para_LineNumber"
54 | }
55 |
56 | panel = {
57 | title:"le-tex – Insert Line Numbers",
58 | stylesTitle:"Select Paragraph Styles",
59 | optionsTitle:"Options",
60 | applyTitle:"Apply to",
61 | startTitle:"Start at",
62 | intervalTitle:"Interval",
63 | intervalFirstLineTitle:"Start numbering with first line",
64 | restartNumPageTitle:"Restart numbering each page",
65 | restartNumFrameTitle:"Restart numbering each frame",
66 | ignoreEmptyLinesTitle:"Ignore empty lines",
67 | radioDocumentTitle:"Document",
68 | radioStoryTitle:"Selected Story",
69 | radioTextFrameTitle:"Selected Text Frame",
70 | lineNumberStylesTitle:"Line Number Styles",
71 | lineNumberObjStyleTitle:"Object Style",
72 | lineNumberParaStyleTitle:"Paragraph Style",
73 | buttonAddNumbersTitle:"Add Numbers",
74 | buttonRemoveNumbersTitle:"Remove all numbers",
75 | buttonCancelTitle:"Cancel",
76 | successMessage:" line numbers inserted.",
77 | removeMessage:" line numbers removed.",
78 | }
79 |
80 | main();
81 |
82 | function main(){
83 | // open file dialog and load a document
84 | if (app.layoutWindows.length == 0) {
85 | var file = File.openDialog ("Select a file", "InDesign:*.indd;*.indb;*.idml, InDesign Document:*.indd, InDesign Book:*.indb, InDesign Markup:*.idml", true)
86 | try {
87 | app.open(File(file));
88 | } catch (e) {
89 | alert(e);
90 | return;
91 | };
92 | }
93 | var doc = app.documents[0];
94 | // check if document is saved
95 | if ((!doc.saved || doc.modified)) {
96 | if ( confirm ("The document needs to be saved.", undefined, "Document not saved.")) {
97 | try {
98 | var userLevel = app.scriptPreferences.userInteractionLevel;
99 | app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
100 | doc = doc.save();
101 | app.scriptPreferences.userInteractionLevel = userLevel;
102 | } catch (e) {
103 | alert ("The document couldn't be saved.\n" + e);
104 | return;
105 | }
106 | }
107 | else {
108 | return;
109 | }
110 | }
111 | // show window
112 | try {
113 | drawWindow(doc);
114 | } catch (e) {
115 | alert ("Error:\n" + e);
116 | }
117 | }
118 |
119 | function drawWindow (doc) {
120 |
121 | var paraStyles = app.documents[0].allParagraphStyles.sort();
122 |
123 | var myWindow = new Window ("palette", panel.title, undefined);
124 | myWindow.orientation = "row";
125 | myWindow.alignChildren = "fill";
126 | // select styles panel
127 | var stylesGroup = myWindow.add ("group {alignChildren: ['left', 'fill']}");
128 | var stylesGroupPanel = stylesGroup.add ("panel", undefined, panel.stylesTitle);
129 | var stylesGroupList = stylesGroupPanel.add ("listbox", undefined, undefined, {multiselect: true});
130 | stylesGroupList.alignment = "fill";
131 | stylesGroupList.preferredSize = [200, 325];
132 |
133 | for (i = 0; i < paraStyles.length; i++){
134 | if(i < paraStyles.length && paraStyles[i].name != options.lineNumberParaStyleName){
135 | var listitem = stylesGroupList.add ("item");
136 | listitem.text = paraStyles[i].name;
137 | }
138 | }
139 | // options panel
140 | var optionsGroup = myWindow.add ("group {orientation: 'column'}");
141 | var optionsGroupPanel = optionsGroup.add ("panel", undefined, panel.optionsTitle);
142 | optionsGroupPanel.alignment = "fill";
143 | optionsGroupPanel.alignChildren = "fill";
144 | var optionsGroupPanelStartGroup = optionsGroupPanel.add ("group {orientation: 'row'}");
145 | var optionsGroupPanelInputStart = optionsGroupPanelStartGroup.add ("edittext", undefined, options.startFrom);
146 | optionsGroupPanelInputStart.characters = 3;
147 | optionsGroupPanelStartGroup.add ("statictext", undefined, panel.startTitle);
148 | var optionsGroupPanelIntervalGroup = optionsGroupPanel.add ("group {orientation: 'row'}");
149 | var optionsGroupPanelInputInterval = optionsGroupPanelIntervalGroup.add ("edittext", undefined, options.interval);
150 | optionsGroupPanelInputInterval.characters = 3;
151 | optionsGroupPanelIntervalGroup.add ("statictext", undefined, panel.intervalTitle);
152 | var optionsGroupPanelInputIntervalFirstLine = optionsGroupPanel.add ("checkbox", undefined, panel.intervalFirstLineTitle);
153 | optionsGroupPanelInputIntervalFirstLine.value = 1;
154 | optionsGroupPanelInputIntervalFirstLine.enabled = optionsGroupPanelInputInterval.text == "1" ? false : true;
155 | optionsGroupPanelInputInterval.onChanging = function(){
156 | if(optionsGroupPanelInputInterval.text == "1"){
157 | optionsGroupPanelInputIntervalFirstLine.enabled = false;
158 | optionsGroupPanelInputIntervalFirstLine.value = 1;
159 | }else{
160 | optionsGroupPanelInputIntervalFirstLine.enabled = true;
161 | }
162 | }
163 | var optionsGroupPanelRestartNumPage = optionsGroupPanel.add ("checkbox", undefined, panel.restartNumPageTitle);
164 | optionsGroupPanelRestartNumPage.value = options.restartNumPage;
165 | optionsGroupPanelRestartNumPage.enabled = (options.restartNumFrame == 1) ? false : true;
166 | var optionsGroupPanelRestartNumFrame = optionsGroupPanel.add ("checkbox", undefined, panel.restartNumFrameTitle);
167 | optionsGroupPanelRestartNumFrame.value = options.restartNumFrame;
168 | optionsGroupPanelRestartNumFrame.onClick = function(){
169 | if(optionsGroupPanelRestartNumFrame.value == 1){
170 | optionsGroupPanelRestartNumPage.enabled = false;
171 | optionsGroupPanelRestartNumPage.value = 1;
172 | }else{
173 | optionsGroupPanelRestartNumPage.enabled = true;
174 | }
175 | }
176 | var optionsGroupPanelIgnoreEmptyLines = optionsGroupPanel.add ("checkbox", undefined, panel.ignoreEmptyLinesTitle);
177 | optionsGroupPanelIgnoreEmptyLines.value = options.ignoreEmptyLines;
178 | // panel apply to
179 | var optionsGroupApplyToGroup = optionsGroup.add ("panel", undefined, panel.applyTitle);
180 | optionsGroupApplyToGroup.alignment = "fill";
181 | optionsGroupApplyToGroup.alignChildren = "left";
182 | optionsGroupApplyToGroup.add ("radiobutton", undefined, panel.radioDocumentTitle);
183 | optionsGroupApplyToGroup.add ("radiobutton", undefined, panel.radioStoryTitle);
184 | optionsGroupApplyToGroup.add ("radiobutton", undefined, panel.radioTextFrameTitle);
185 | optionsGroupApplyToGroup.children[options.applyTo].value =true;
186 | // panel style names
187 | var optionsGroupPanelLineNumberStyles = optionsGroup.add ("panel", undefined, panel.lineNumberStylesTitle);
188 | optionsGroupPanelLineNumberStyles.orientation = "column";
189 | optionsGroupPanelLineNumberStyles.alignment = "fill";
190 | optionsGroupPanelLineNumberStyles.alignChildren = "fill";
191 | var optionsGroupPanelLineObjStyleGroup = optionsGroupPanelLineNumberStyles.add("group");
192 | var lineNumberObjStyleInput = optionsGroupPanelLineObjStyleGroup.add ("edittext", undefined, options.lineNumberObjStyleName);
193 | var optionsGroupPanelParaStyle = optionsGroupPanelLineObjStyleGroup.add ("statictext", undefined, panel.lineNumberObjStyleTitle);
194 | lineNumberObjStyleInput.characters = 20;
195 | var optionsGroupPanelLineParaStyleGroup = optionsGroupPanelLineNumberStyles.add("group");
196 | var lineNumberParaStyleInput = optionsGroupPanelLineParaStyleGroup.add ("edittext", undefined, options.lineNumberParaStyleName);
197 | var optionsGroupPanelParaStyle = optionsGroupPanelLineParaStyleGroup.add ("statictext", undefined, panel.lineNumberParaStyleTitle);
198 |
199 | lineNumberParaStyleInput.characters = 20;
200 | // button group
201 | var buttonGroup = myWindow.add ("group {orientation: 'column', alignChildren: 'fill'}");
202 | var buttonAddNumbers = buttonGroup.add("button", undefined, panel.buttonAddNumbersTitle);
203 | buttonAddNumbers.enabled = true;
204 | var buttonRemoveNumbers = buttonGroup.add("button", undefined, panel.buttonRemoveNumbersTitle);
205 | var buttonCancel = buttonGroup.add("button", undefined, panel.buttonCancelTitle);
206 | buttonCancel.alignment = ["fill","bottom"];
207 | buttonAddNumbers.onClick = function(){
208 |
209 | options.styles = stylesGroupList.selection;
210 | options.restartNumPage = optionsGroupPanelRestartNumPage.value;
211 | options.restartNumFrame = optionsGroupPanelRestartNumFrame.value;
212 | options.ignoreEmptyLines = optionsGroupPanelIgnoreEmptyLines.value;
213 | options.startFrom = parseInt(optionsGroupPanelInputStart.text);
214 | options.interval = parseInt(optionsGroupPanelInputInterval.text);
215 | options.intervalFirstLine = optionsGroupPanelInputIntervalFirstLine.value;
216 | options.applyTo = selectedRadio(optionsGroupApplyToGroup);
217 | options.lineNumberObjStyleName = lineNumberObjStyleInput.text;
218 | options.lineNumberParaStyleName = lineNumberParaStyleInput.text;
219 | // intialize line numbering
220 | if(options.styles == null){
221 | alert("Please select one or more paragraph styles.")
222 | } else {
223 | try{
224 | addNumbers(options);
225 | alert(options.counter + panel.successMessage);
226 | } catch(e){
227 | alert(e);
228 | }
229 | }
230 | }
231 | buttonRemoveNumbers.onClick = function(){
232 | options.lineNumberObjStyleName = lineNumberObjStyleInput.text;
233 | removeNumbers(options);
234 | }
235 |
236 | buttonCancel.onClick = function() {
237 | myWindow.close();
238 | }
239 | return myWindow.show();
240 | }
241 |
242 | function removeNumbers(options){
243 | var doc = app.activeDocument;
244 | var stories = doc.stories;
245 | var counter = 0;
246 | for (i = 0; i < stories.length; i++){
247 | var currentStory = stories[i];
248 | var textFrames = currentStory.textFrames.everyItem().getElements();
249 | for (j = 0; j < textFrames.length; j++){
250 | var currentTextFrame = textFrames[j];
251 | if(currentTextFrame.appliedObjectStyle.name == options.lineNumberObjStyleName){
252 | currentTextFrame.remove();
253 | counter = counter +=1
254 | }
255 | }
256 | }
257 | alert(counter + panel.removeMessage)
258 | return;
259 | }
260 |
261 |
262 | function addNumbers(options) {
263 | var doc = app.activeDocument;
264 | // startFromTemp needed for saving last line number of frame
265 | options.startFromTemp = options.startFrom;
266 |
267 | // create styles, later they are applied
268 | if(!doc.objectStyles.itemByName(options.lineNumberObjStyleName).isValid){
269 | var lineNumberObjStyle = doc.objectStyles.add();
270 | lineNumberObjStyle.name = options.lineNumberObjStyleName;
271 | }
272 | if(!doc.paragraphStyles.itemByName(options.lineNumberParaStyleName).isValid){
273 | var lineNumberParaStyle = doc.paragraphStyles.add();
274 | lineNumberParaStyle.name = options.lineNumberParaStyleName;
275 | }
276 | // add line numbers to entire document
277 | if(options.applyTo == 0){
278 | var scope = addNumbersToDocument(doc, options);
279 | // .. to story
280 | } else if (options.applyTo == 1){
281 | var scope = addNumbersToStory(doc, app.selection[0].parentStory, options);
282 | // .. to text frame
283 | } else if(app.selection[0] && app.selection[0].constructor.name == "TextFrame") {
284 | var scope = addNumbersToTextFrame(doc, app.selection[0], options);
285 | } else if(app.selection[0] && app.selection[0].hasOwnProperty("parentTextFrames") && app.selection[0].parentTextFrames.length == 1 ) {
286 | var scope = addNumbersToTextFrame(doc, app.selection[0].parentTextFrames[0], options);
287 | } else {
288 | return alert("No Text Frame selected.");
289 | }
290 | return;
291 | }
292 |
293 | function addNumbersToDocument(doc, options) {
294 | var stories = doc.stories;
295 | for (i = 0; i < stories.length; i++){
296 | currentStory = stories[i];
297 | addNumbersToStory(doc, currentStory, options);
298 | }
299 | }
300 |
301 | function addNumbersToStory(doc, story, options){
302 | var textContainers = story.textContainers;
303 | for (j = 0; j < textContainers.length; j++){
304 | currentTextFrame = textContainers[j];
305 | // exclude all frames with a line number object style
306 | if(currentTextFrame.appliedObjectStyle.name != options.lineNumberObjStyleName && currentTextFrame.parentPage != null){
307 | addNumbersToTextFrame(doc, currentTextFrame, options);
308 | }
309 | }
310 | }
311 |
312 | function addNumbersToTextFrame(doc, textFrame, options){
313 | var currentPageOffset = textFrame.parentPage.documentOffset;
314 | var pageBreakBoolean = currentPageOffset != options.pageOffset;
315 | options.pageOffset = currentPageOffset;
316 | var lines = textFrame.lines;
317 | var penalty = 0;
318 | // discontinue line numbering at page breaks when corresponding option is set
319 | var start = (pageBreakBoolean && options.restartNumPage == 1) ? options.startFrom : options.startFromTemp;
320 |
321 | for (k = 0; k < lines.length; k++){
322 | var currentLine = lines[k];
323 | var lineParaStyle = currentLine.appliedParagraphStyle.name;
324 |
325 | // penalty for empty lines
326 | penalty = ((!inArray(lineParaStyle, options.styles) && ( !(isLineEmpty(currentLine.contents) && options.ignoreEmptyLines == 1)))
327 | || (isLineEmpty(lines[k-1].contents) && options.ignoreEmptyLines == 1)
328 | ) ? penalty +=1 : penalty;
329 |
330 | // calculate line number
331 | var lineNumber = k + start - penalty;
332 |
333 | // remember last line if numbering should be contiuned for next frame
334 | options.startFromTemp = (options.restartNumFrame == 1) ? options.startFromTemp : lineNumber + 1;
335 | var lineNumberStr = lineNumber.toString();
336 |
337 | if(!Boolean(isLineEmpty(currentLine.contents) && options.ignoreEmptyLines == 1)
338 | && inArray(lineParaStyle, options.styles)
339 | && (lineNumber % options.interval == 0) || (lineNumber == 1 && options.intervalFirstLine == 1)){
340 |
341 | options.counter = options.counter += 1
342 |
343 | // place insertion point depending on blank lines
344 | var anchoredFrame = (currentLine.contents.match(/^\s*$/) == null) ? currentLine.insertionPoints[1].textFrames.add() : currentLine.insertionPoints[0].textFrames.add();
345 |
346 | anchoredFrame.contents = lineNumberStr;
347 | anchoredFrame.paragraphs[0].appliedParagraphStyle = doc.paragraphStyles.itemByName(options.lineNumberParaStyleName);
348 |
349 | fitTextFrameProportionally(anchoredFrame, 0.01);
350 | anchoredFrame.fit(FitOptions.FRAME_TO_CONTENT);
351 |
352 | // apply object style
353 | anchoredFrame.appliedObjectStyle = doc.objectStyles.itemByName(options.lineNumberObjStyleName);
354 |
355 | // anchored object settings, can be overwritten with object style
356 | var anchoredFrameObjSettings = anchoredFrame.anchoredObjectSettings
357 | anchoredFrameObjSettings.anchoredPosition = AnchorPosition.ANCHORED;
358 | anchoredFrameObjSettings.horizontalReferencePoint = AnchoredRelativeTo.TEXT_FRAME;
359 | anchoredFrameObjSettings.horizontalAlignment = HorizontalAlignment.LEFT_ALIGN;
360 | anchoredFrameObjSettings.verticalReferencePoint = VerticallyRelativeTo.LINE_BASELINE;
361 | anchoredFrameObjSettings.verticalAlignment = VerticalAlignment.BOTTOM_ALIGN;
362 | // place relative to spine
363 | anchoredFrameObjSettings.spineRelative = true;
364 | anchoredFrameObjSettings.anchorXoffset = 5;
365 | anchoredFrameObjSettings.anchorYoffset = 0;
366 |
367 | anchoredFrame.strokeWeight = 0;
368 |
369 | }
370 |
371 | }
372 | //return;
373 | }
374 |
375 | // return array from groups with children input elements
376 | function selectedRadio (inputGroup) {
377 | var arr = []
378 | for(var i = 0; i < inputGroup.children.length; i++) {
379 | if(inputGroup.children[i].value == true){
380 | arr.push(i);
381 | }
382 | }
383 | return arr;
384 | }
385 |
386 | function inArray(item,array){
387 | for(l=0; l < array.length; l++){
388 | if( array[l].toString() === item){
389 | return true;
390 | }
391 | }
392 | return false;
393 | }
394 |
395 | function isLineEmpty(line){
396 | if(line.match(/^(\n|\s)*$/)){
397 | return true;
398 | } else {
399 | return false;
400 | }
401 | }
402 |
403 | function resize(textFrame, by) {
404 | textFrame.resize(CoordinateSpaces.INNER_COORDINATES, AnchorPoint.TOP_LEFT_ANCHOR, ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY, [by, by]);
405 | }
406 |
407 | function fitTextFrameProportionally(textFrame, factor) {
408 | if (textFrame.overflows) {
409 | while (textFrame.overflows) {
410 | resize(textFrame, 1 + factor);
411 | }
412 | }
413 | else {
414 | while (!textFrame.overflows) {
415 | resize(textFrame, 1 - factor);
416 | }
417 | resize(textFrame, 1 / (1 - factor));
418 | }
419 | }
420 |
--------------------------------------------------------------------------------
/link-endnotes/README.md:
--------------------------------------------------------------------------------
1 | # link-endnotes.jsx
2 |
3 | A script for Adobe InDesign to automatically and sectionwise create hyperlinks between reference and endnote paragraphs .
4 |
5 | ## Installation
6 |
7 | * open InDesign Scripts panel
8 | * right-click on folder entitled "User" and select "Reveal in Explorer/Finder"
9 | * copy link-endnotes.jsx to this folder
10 |
11 | ## Requirements
12 |
13 | * works with Adobe InDesign Version 8.0 (CS6) and later
14 | * not yet tested with earlier versions
15 |
16 | ## Features
17 | * select paragraph styles by which to split document into sections
18 | * assign endnotes to section, provided that endnote heading and section heading are identical
19 | * create link from reference within section to endnote and back
20 |
--------------------------------------------------------------------------------
/link-endnotes/link-endnotes.jsx:
--------------------------------------------------------------------------------
1 | #target indesign
2 |
3 | //LinkEndnotes.jsx
4 | //author: Anna Schmalfuß, le-tex publishing services GmbH
5 | //version: 1.0
6 | //date: 2015-08-27
7 |
8 | //version 1.1
9 | //modified 2015-08-31: create backlinks
10 | //modified 2016-05-23: exactly match style names + specified conditions to process paras
11 |
12 | /*
13 | *
14 | * LICENSE
15 | *
16 | * Copyright (c) 2015, le-tex publishing services GmbH
17 | * All rights reserved.
18 | *
19 | * Redistribution and use in source and binary forms, with or without
20 | * modification, are permitted provided that the following conditions are met:
21 | *
22 | * 1. Redistributions of source code must retain the above copyright notice,
23 | * this list of conditions and the following disclaimer.
24 | *
25 | * 2. Redistributions in binary form must reproduce the above copyright notice,
26 | * this list of conditions and the following disclaimer in the documentation
27 | * and/or other materials provided with the distribution.
28 | *
29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
30 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
35 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 | * POSSIBILITY OF SUCH DAMAGE.
39 | *
40 | */
41 |
42 |
43 | options = {
44 | endnoteTitleStyleName: "Endnote_U1",
45 | endnoteParaStyleName: "Endnote",
46 | chapterStyleName: "U1",
47 | endnoteNumberStyleName: "Endnote_Ziffer",
48 | endnoteRefStyleName: "Endnote_Ref",
49 | endnotePrefixLabel: "en_",
50 | run: 0
51 | }
52 |
53 | var linkCount = 0;
54 | var endnoteNrDestArray = [];
55 | var endnoteRefDestArray = [];
56 |
57 |
58 | if(app.documents.length != 0) {
59 |
60 | var doc = app.activeDocument;
61 | main(doc);
62 |
63 | }
64 |
65 | else{
66 | alert("Error! \r\rNo active document!");
67 | }
68 |
69 |
70 |
71 |
72 |
73 | // ###################### functions
74 |
75 | function main(doc){
76 | if ((!doc.saved || doc.modified)) {
77 | if ( confirm ("The document needs to be saved.", undefined, "Document not saved.")) {
78 | try {
79 | var userLevel = app.scriptPreferences.userInteractionLevel;
80 | app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
81 | doc = doc.save();
82 | app.scriptPreferences.userInteractionLevel = userLevel;
83 | }
84 | catch (e) {
85 | alert ("The document couldn't be saved.\n" + e);
86 | return;
87 | }
88 | }
89 | else {
90 | return;
91 | }
92 | }
93 |
94 | var safetyAlert = confirm("This script deletes any hyperlink and hyperlink\ndestination with the name prefix '" + options.endnotePrefixLabel + "'. \rDo you want to run the script?");
95 | if (safetyAlert == true){
96 |
97 | //remove hyperlinks with prefix en_
98 | for (var i = doc.hyperlinks.length - 1; i >= 0; i-- ) {
99 | var link = doc.hyperlinks[i];
100 | var source = link.source;
101 | if(link.name.match(/^en_/g) ){
102 | link.remove();
103 | source.remove();
104 | }
105 | }
106 |
107 | // remove destinations with prefix en_
108 | for (var i = doc.hyperlinkTextDestinations.length - 1; i >= 0; i--) {
109 | var dest = doc.hyperlinkTextDestinations[i]
110 | if(dest.name.match(/^en_/g)){
111 | dest.remove();
112 | }
113 | }
114 |
115 | // draw UI
116 | try {
117 | ui(doc);
118 | }
119 | catch (e) {
120 | alert (e);
121 | }
122 |
123 | //run script
124 | if(options.run != 0){
125 | run (options);
126 | }
127 | }
128 | }
129 |
130 |
131 | function ui(doc){
132 | var dialog = new Window ("dialog", "Link endnotes");
133 | dialog.alignChildren = "left";
134 |
135 | var pstyles = doc.allParagraphStyles;
136 | var pStylesArray = [];
137 | for (a = 0; a < pstyles.length; a ++){
138 | pStylesArray.push (pstyles[a].name);
139 | }
140 |
141 | var cstyles = doc.allCharacterStyles;
142 | var cStylesArray = [];
143 | for (a = 0; a < cstyles.length; a ++){
144 | cStylesArray.push (cstyles[a].name);
145 | }
146 |
147 | var panel1 = dialog.add( "panel", undefined, "Paragraph styles for sectionwise splitting")
148 | panel1.preferredSize.width = 450;
149 | panel1.orientation = 'column';
150 | panel1.spacing = 10;
151 | panel1.alignChildren = "left";
152 |
153 | var row1 = panel1.add("group");
154 | row1.add("statictext", undefined, "Headline style in main text");
155 | var list1 = row1.add ("dropdownlist", undefined, pStylesArray);
156 | list1.selection = 0;
157 |
158 | var row2 = panel1.add("group");
159 | row2.add("statictext", undefined, "Headline style in appendix");
160 | var list2 = row2.add ("dropdownlist", undefined, pStylesArray);
161 | list2.selection = 0;
162 |
163 | var panel2 = dialog.add( "panel", undefined, "Endnote styles")
164 | panel2.preferredSize.width = 450;
165 | panel2.orientation = 'column';
166 | panel2.spacing = 10;
167 | panel2.alignChildren = "left";
168 |
169 | var row3 = panel2.add("group");
170 | row3.add("statictext", undefined, "Paragraph style of endnotes");
171 | var list3 = row3.add ("dropdownlist", undefined, pStylesArray);
172 | list3.preferredSize.width = 175;
173 | list3.selection = 0;
174 |
175 | var row4 = panel2.add("group");
176 | row4.add("statictext", undefined, "Character style of endnote reference");
177 | var list4 = row4.add ("dropdownlist", undefined, cStylesArray);
178 | list4.preferredSize.width = 175;
179 | list4.selection = 0;
180 |
181 | var row5 = panel2.add("group");
182 | row5.add("statictext", undefined, "Character style of endnote number");
183 | var list5 = row5.add ("dropdownlist", undefined, cStylesArray);
184 | list5.preferredSize.width = 175;
185 | list5.selection = 0;
186 |
187 | var buttons = dialog.add ("group")
188 | var ok = buttons.add ("button", undefined, "OK", {name: "ok"});
189 | var esc = buttons.add ("button", undefined, "Cancel", {name: "esc"});
190 |
191 | ok.onClick = function() {
192 | if (list1.selection === null || list2.selection === null || list3.selection === null || list4.selection === null || list5.selection === null){
193 | alert("Error while selecting paragraph and character styles.");
194 | }
195 | else {
196 | options.chapterStyleName = list1.selection.text.replace(/(~.+)?/g, "");
197 | options.endnoteTitleStyleName = list2.selection.text.replace(/(~.+)?/g, "");
198 | options.endnoteParaStyleName = list3.selection.text.replace(/(~.+)?/g, "");
199 | options.endnoteRefStyleName = list4.selection.text.replace(/(~.+)?/g, "");
200 | options.endnoteNumberStyleName = list5.selection.text.replace(/(~.+)?/g, "");
201 | checkSelection(options);
202 | options.run = 1;
203 | dialog.close();
204 | };
205 | }
206 | return dialog.show();
207 | }
208 |
209 |
210 | function checkSelection(options){
211 | if(options.chapterStyleName == options.endnoteTitleStyleName){
212 | alert("Section and endnote headline styles are identical. This may cause incorrect linking.");
213 | }
214 | if(options.endnoteRefStyleName == options.endnoteNumberStyleName){
215 | alert("Endote reference and number styles are identical. This may cause incorrect linking.");
216 | }
217 | return;
218 | }
219 |
220 |
221 | function run(options){
222 | // collect styles with identical base name (without tilde)
223 | options.endnoteParaStylePattern = eval("/^" + options.endnoteParaStyleName + "(~.+)?$/g");
224 | options.chapterStylePattern = eval("/^" + options.chapterStyleName + "(~.+)?$/g");
225 | options.endnoteTitleStylePattern = eval("/^" + options.endnoteTitleStyleName + "(~.+)?$/g");
226 |
227 | // progress bar
228 | var msgTitle = {de:"Schritt 1/2: Find and create link destinations"};
229 | var progress = new Window('palette', localize(msgTitle) );
230 | progress.frameLocation = [400,275];
231 | progress.bar = progress.add('progressbar');
232 | progress.bar.size = [400,15];
233 | progress.bar.value = 0;
234 | progress.bar.maxvalue = doc.allPageItems.length;
235 | progress.file = progress.add('statictext');
236 | progress.file.size = [400,15];
237 | progress.show();
238 |
239 | for(var i = 0; i < doc.stories.length; i++){
240 | var story = doc.stories[i];
241 |
242 | for (var k = 0; k < story.paragraphs.length; k++){
243 | var para = story.paragraphs[k];
244 |
245 | if(para.appliedParagraphStyle.name.match(options.endnoteTitleStylePattern) && para.contents.match(/\S/g)){
246 | // Whitespace und Umbruchzeichen entfernen (000A = harter Umbruch, 00AD = bedingter Zeilenumbruch, 200B = bedingter Zeilenumbruch ohne Trennstrich, FEFF = Tagklammern)
247 | var endnotesTitle = para.contents.replace(/\s|[\u000A\u00AD\u200B\uFEFF]/g, "");
248 | var endnotesTitleForProgress = para.contents.replace(/[\u000A\u00AD\u200B\uFEFF]/g, "");
249 | //alert("endnotesTitle: " + endnotesTitle);
250 | }
251 |
252 |
253 | if(para.appliedParagraphStyle.name.match(options.endnoteParaStylePattern) && endnotesTitle){
254 | endnoteNrDestArray = findLinkdestinations(para, options.endnoteNumberStyleName, options.endnotePrefixLabel, "a", endnoteNrDestArray, endnotesTitle);
255 | progress.bar.value++;
256 | progress.file.text = endnotesTitleForProgress;
257 | }
258 |
259 |
260 | if(para.appliedParagraphStyle.name.match(options.chapterStylePattern) && para.contents.match(/\S/g)){
261 | var chapterTitle = para.contents.replace(/\s|[\u000A\u00AD\u200B\uFEFF]/g, "");
262 | var chapterTitleForProgress = para.contents.replace(/[\u000A\u00AD\u200B\uFEFF]/g, "");
263 | }
264 |
265 | if(!para.appliedParagraphStyle.name.match(options.chapterStylePattern) &&
266 | !para.appliedParagraphStyle.name.match(options.endnoteParaStylePattern) &&
267 | !para.appliedParagraphStyle.name.match(options.endnoteTitleStylePattern) &&
268 | chapterTitle && para.contents.match(/\S/g)){
269 | //alert("Kapiteltitel: " + chapterTitle);
270 | endnoteRefDestArray = findLinkdestinations(para, options.endnoteRefStyleName, options.endnotePrefixLabel, "b", endnoteRefDestArray, chapterTitle);
271 | progress.bar.value++;
272 | progress.file.text = chapterTitleForProgress;
273 | }
274 |
275 | }
276 | }
277 | progress.close();
278 |
279 |
280 | // progress bar
281 | var msgTitle = {de:"Schritt 2/2: Find and link references"};
282 | var progress = new Window('palette', localize(msgTitle) );
283 | progress.frameLocation = [400,275];
284 | progress.bar = progress.add('progressbar');
285 | progress.bar.size = [400,15];
286 | progress.bar.value = 0;
287 | progress.bar.maxvalue = doc.allPageItems.length;
288 | progress.file = progress.add('statictext');
289 | progress.file.size = [400,15];
290 | progress.show();
291 |
292 | for(var i = 0; i < doc.stories.length; i++){
293 | var story = doc.stories[i]
294 |
295 | for (var k = 0; k < story.paragraphs.length; k++){
296 | var para = story.paragraphs[k];
297 |
298 |
299 | if(para.appliedParagraphStyle.name.match(options.chapterStylePattern) && para.contents.match(/\S/g)){
300 | var chapterTitle = para.contents.replace(/\s|[\u000A\u00AD\u200B\uFEFF]/g, "");
301 | var chapterTitleForProgress = para.contents.replace(/[\u000A\u00AD\u200B\uFEFF]/g, "");
302 | }
303 |
304 | //alert("Kapiteltitel: " + chapterTitle);
305 | if(!para.appliedParagraphStyle.name.match(options.chapterStylePattern) &&
306 | !para.appliedParagraphStyle.name.match(options.endnoteParaStylePattern) &&
307 | !para.appliedParagraphStyle.name.match(options.endnoteTitleStylePattern) &&
308 | chapterTitle && para.contents.match(/\S/g)){
309 | linkCount = createLinks(para, options.endnoteRefStyleName, options.endnotePrefixLabel, "a", chapterTitle, linkCount);
310 | progress.bar.value++;
311 | progress.file.text = chapterTitleForProgress;
312 | }
313 |
314 | if(para.appliedParagraphStyle.name.match(options.endnoteTitleStylePattern) && para.contents.match(/\S/g)){
315 | // Whitespace und Umbruchzeichen entfernen (000A = harter Umbruch, 00AD = bedingter Zeilenumbruch, 200B = bedingter Zeilenumbruch ohne Trennstrich, FEFF = Tagklammern)
316 | var endnotesTitle = para.contents.replace(/\s|[\u000A\u00AD\u200B\uFEFF]/g, "");
317 | var endnotesTitleForProgress = para.contents.replace(/[\u000A\u00AD\u200B\uFEFF]/g, "");
318 | }
319 |
320 | //alert("endnotesTitle: " + endnotesTitle);
321 | if(para.appliedParagraphStyle.name.match(options.endnoteParaStylePattern) && endnotesTitle){
322 | linkCount = createLinks(para, options.endnoteNumberStyleName, options.endnotePrefixLabel, "b", endnotesTitle, linkCount);
323 | progress.bar.value++;
324 | progress.file.text = endnotesTitleForProgress;
325 | }
326 |
327 |
328 | }
329 |
330 | }
331 | progress.close();
332 |
333 | alert(linkCount + " hyperlinks have been created.")
334 | }
335 |
336 |
337 |
338 | function findLinkdestinations (para, grepStyleName, prefixLabel, id, destArray, title){
339 | app.findGrepPreferences = NothingEnum.nothing;
340 | app.changeGrepPreferences = NothingEnum.nothing;
341 | app.findChangeGrepOptions.properties = {includeFootnotes:true, includeMasterPages:false, includeHiddenLayers:true, includeLockedStoriesForFind:true, includeLockedLayersForFind:true};
342 | app.findGrepPreferences.findWhat = "\\d+";
343 | var foundItems = new Array();
344 | foundItems = para.findGrep();
345 | app.findGrepPreferences = NothingEnum.nothing;
346 | app.changeGrepPreferences = NothingEnum.nothing;
347 | var foundItemsArray = [];
348 | for (var i = 0; i < foundItems.length; i++ ) {
349 | var pattern = eval("/^" + grepStyleName + "/g");
350 | var charStyleCheck = foundItems[i].appliedCharacterStyle.name.match(pattern);
351 | if(charStyleCheck) {
352 | var content = foundItems[i].contents;
353 | var ip = foundItems[i].insertionPoints[-1];
354 | foundItemsArray.push( {INDEX: i, Content: content, IP: ip, Title:title, source:foundItems[i].texts } );
355 | }
356 | }
357 |
358 | for (var i = foundItemsArray.length - 1; i >= 0; i--) {
359 | var label = prefixLabel + foundItemsArray[i].Content + id + "_"+ title;
360 | try {
361 | var linkDestination = doc.hyperlinkTextDestinations.item(label);
362 | linkDestination.name;
363 | }
364 | catch(e) {
365 | var linkDestination = doc.hyperlinkTextDestinations.add(foundItemsArray[i].IP, {name: label});
366 | /*
367 | foundItemsArray[i].IP.select();
368 | app.activeWindow.zoomPercentage = app.activeWindow.zoomPercentage;
369 | alert(foundItemsArray[i].ID + "\n\n" + e);
370 | */
371 | }
372 | destArray.push( foundItemsArray[i] );
373 | }
374 |
375 | return destArray;
376 | }
377 |
378 |
379 | function createLinks(para, grepStyleName, prefixLabel, id, title, counter){
380 | app.findGrepPreferences = NothingEnum.nothing;
381 | app.changeGrepPreferences = NothingEnum.nothing;
382 | app.findChangeGrepOptions.properties = {includeFootnotes:true, includeMasterPages:false, includeHiddenLayers:true, includeLockedStoriesForFind:true, includeLockedLayersForFind:true};
383 | app.findGrepPreferences.findWhat = "\\d+";
384 | var foundItems = new Array();
385 | foundItems = para.findGrep();
386 | app.findGrepPreferences = NothingEnum.nothing;
387 | app.changeGrepPreferences = NothingEnum.nothing;
388 |
389 | for (var i = 0; i < foundItems.length; i++ ) {
390 | var pattern = eval("/^" + grepStyleName + "/g");
391 | var charStyleCheck = foundItems[i].appliedCharacterStyle.name.match(pattern);
392 | if(charStyleCheck) {
393 |
394 | var linkDest = doc.hyperlinkTextDestinations.item(prefixLabel + foundItems[i].contents + id + "_"+ title);
395 |
396 | if(linkDest != null){
397 | try{
398 | //alert("linkname: " + prefixLabel + foundItems[i].contents + id + "_"+ title);
399 | var linkSource = doc.hyperlinkTextSources.add(foundItems[i].texts);
400 | var linkName = prefixLabel+ foundItems[i].contents + id + "_"+ title.slice(0,20);
401 | doc.hyperlinks.add(linkSource, linkDest, {name: linkName, visible:false});
402 | counter++;
403 | }
404 | catch(e) {
405 | alert(e);
406 | }
407 |
408 | }
409 | else{
410 | alert("Error! \n\nThe hyperlink destination \"" + prefixLabel + foundItems[i].contents + id + "_" + title.slice(0,20) + "\" was not found. \nNo link will be created.");
411 | }
412 |
413 | }
414 | }
415 | return counter;
416 | }
417 |
--------------------------------------------------------------------------------
/pagenames/PageNamesToStoryALL.jsx:
--------------------------------------------------------------------------------
1 | #target indesign
2 |
3 | //
4 | // PageNamesToStoryALL.jsx
5 | // Version 1.3
6 | //
7 | // created by: maqui | 10:18 28.02.2013
8 | // modified by: maqui | 16:59 28.02.2013 (Löschen der Bedingungstexte ohne Einblenden --> Formatierung bleibt 1:1 erhalten)
9 | // modified by: maqui | 16:40 16.06.2014 Alle Textabschnitte erhalten die Seitenzahl-Infos
10 | // modified by: maqui | 11:00 21.05.2015 Debug (bedingten Text "PageStart" und "PageEnd" löschen, auch wenn er sichtbar ist)
11 | // modified by: gimsieke | 2015-06-07 Add 'CellPage_XY' to table cells
12 | //
13 | // Trägt in jedem Textrahmen (bei jedem Seitenwechsel) den Seitenbeginn bzw. das Seitenende als bedingten Text mit der jeweiligen Seitenzahl ein.
14 | //
15 | //
16 |
17 | var myPageStartTag = "PageStart";
18 | var myPageEndTag = "PageEnd";
19 |
20 | //var myStartSwatchName = "PageStart";
21 | //var myEndSwatchName = "PageEnd";
22 |
23 | var myCondSetOnName = "PageNumber_On";
24 | var myCondSetOffName = "PageNumber_Off";
25 |
26 | main(); // ==>
27 |
28 | function main(){
29 | if(app.documents.length != 0){
30 | var myDoc = app.activeDocument;
31 | var myPage;
32 |
33 | // Bedingungen definieren
34 | var myStartCond = newCondition(myDoc, myPageStartTag);
35 | myStartCond.indicatorMethod = ConditionIndicatorMethod.USE_HIGHLIGHT;
36 | myStartCond.indicatorColor = UIColors.GOLD;
37 | var myEndCond = newCondition(myDoc, myPageEndTag); // ==>
38 | myEndCond.indicatorMethod = ConditionIndicatorMethod.USE_HIGHLIGHT;
39 | myEndCond.indicatorColor = UIColors.LAVENDER;
40 |
41 | // Sets definieren
42 | if(checkConditionSet(myDoc, myCondSetOnName)) myDoc.conditionSets.item(myCondSetOnName).remove();
43 | if(checkConditionSet(myDoc, myCondSetOffName)) myDoc.conditionSets.item(myCondSetOffName).remove();
44 | var myOnSettingArray = [[myStartCond, true], [myEndCond, true]];
45 | var myOffSettingArray = [[myStartCond, false], [myEndCond, false]];
46 | var myCondSetOn = myDoc.conditionSets.add({name:myCondSetOnName, setConditions:myOnSettingArray});
47 | var myCondSetOff = myDoc.conditionSets.add({name:myCondSetOffName, setConditions:myOffSettingArray});
48 | myDoc.conditionalTextPreferences.properties = {activeConditionSet:myCondSetOn};
49 | myCondSetOn.redefine();
50 | myDoc.conditionalTextPreferences.properties = {activeConditionSet:myCondSetOff};
51 | myCondSetOff.redefine();
52 |
53 | // Farben für bedingten Text (als Orientierungshilfe)
54 | /*if (checkSwatch(myDoc, myStartSwatchName) == false) myDoc.colors.add({name:myStartSwatchName, colorValue:[0,0,255], model:ColorModel.PROCESS, space:ColorSpace.RGB});
55 | if (checkSwatch(myDoc, myEndSwatchName) == false) myDoc.colors.add({name:myEndSwatchName, colorValue:[255,0,0], model:ColorModel.PROCESS, space:ColorSpace.RGB});
56 | var myStartSwatch = myDoc.swatches.itemByName(myStartSwatchName);
57 | var myEndSwatch = myDoc.swatches.itemByName(myEndSwatchName);*/
58 | var myStartCounter = 0;
59 | var myEndCounter = 0;
60 | for (var i = 0; i < myDoc.stories.length; i++) {
61 | var myStory = myDoc.stories[i];
62 | var myMasterSpreadFlag = true;
63 | for (var j = 0; j < myStory.textContainers.length; j++) {
64 | var myTestFrame = myStory.textContainers[j];
65 | // Wenn ein Textrahmen nicht auf der Montagefläche ...
66 | if(myTestFrame.hasOwnProperty("parentPage") && myTestFrame.parentPage != null) {
67 | // ... überprüfen, ob auf Musterseite
68 | if(myTestFrame.parentPage.parent.constructor.name != "MasterSpread" && myStory.textContainers.length > 0) {
69 | myMasterSpreadFlag = false;
70 | break;
71 | }
72 | }
73 | }
74 | // Wenn Textabschnitt sich nicht auf einer Musterseite befindet, ...
75 | if(!myMasterSpreadFlag && myStory.textContainers.length > 0) {
76 | // Alle Textrahmen vom Textabschnitt durchlaufen ...
77 | var myFrame = myStory.textContainers[myStory.textContainers.length - 1];
78 | var myOldPage = false; // wenn nicht als "false" definiert, ist myOldPage letzter "Page"-Wert???????????????????????
79 | var myOldFirstIP = false;
80 | while (myFrame != null) {
81 | var myPage = myFrame.parentPage;
82 | // Wenn Textabschnitt sich nicht auf Montagefläche ...
83 | if(myPage != null && myFrame.constructor.name == "TextFrame" && myFrame.insertionPoints.length > 0) {
84 | // PageEnd
85 | // Ist Rahmen auf anderer Seite? ... Wenn ja, dann PageEnd-Tag setzen
86 | if(myPage != myOldPage) {
87 | var myLastContent = myPageEndTag + "_" + myPage.name;
88 | if(myOldFirstIP) {
89 | //var myLastIP = myOldFirstIP.parentStory.insertionPoints.previousItem(myOldFirstIP);
90 | var myLastIP = myOldFirstIP.parentStory.insertionPoints[myOldID - 1];
91 | //var myLastID = myLastIP.parentStory.insertionPoints.itemByRange(0, myLastIP.index).insertionPoints.length;
92 | //alert(myOldID + "\n" + myLastID);
93 | }
94 | else {
95 | var myLastIP = myFrame.insertionPoints.lastItem();
96 | //myFrame.select();
97 | //app.activeWindow.zoomPercentage = app.activeWindow.zoomPercentage;
98 | //alert(myLastContent + " :: " + myOldPage.constructor.name);
99 | }
100 | myLastIP.contents = myLastContent;
101 | //myLastIP.fillColor = myEndSwatch;
102 | myLastIP.applyConditions(myEndCond, true);
103 | myEndCounter++;
104 | }
105 | // PageStart
106 | // Ist vorheriger Rahmen auf anderer Seite? ... Wenn ja, dann PageStart-Tag setzen
107 | if (checkPrevFrame(myFrame, myPage)) {
108 | var myFirstContent = myPageStartTag + "_" + myPage.name;
109 | var myFirstIP = myFrame.insertionPoints.firstItem();
110 | var myOldFirstIP = myFirstIP; // IP merken, da er sich bei evtl. Umbruchveränderungen verschiebt
111 | var myOldID = myOldFirstIP.parentStory.insertionPoints.itemByRange(0, myOldFirstIP.index).insertionPoints.length;
112 | myFirstIP.contents = myFirstContent;
113 | //myFirstIP.fillColor = myStartSwatch;
114 | myFirstIP.applyConditions(myStartCond, true);
115 | myStartCounter++;
116 | }
117 | myOldPage = myPage;
118 | }
119 | var myFrame = myFrame.previousTextFrame;
120 | }
121 | }
122 |
123 | // Process all table cells in the story since they won't be included in the frame iteration:
124 | if(!myMasterSpreadFlag && myStory.tables.length > 0) {
125 | for (var t = 0; t < myStory.tables.length; t++) {
126 | for (var c = 0; c < myStory.tables[t].cells.length; c++) {
127 | var myCell = myStory.tables[t].cells[c];
128 | var firstCellChar = myCell.characters[0];
129 | if (firstCellChar != null) {
130 | var myFrame = firstCellChar.parentTextFrames[0];
131 | if (myFrame != null) {
132 | var myPage = myFrame.parentPage;
133 | var myIP = myCell.insertionPoints.firstItem();
134 | myIP.contents = "CellPage_" + myPage.name;
135 | //myIP.fillColor = myStartSwatch;
136 | myIP.applyConditions(myStartCond, true);
137 | }
138 | }
139 | }
140 | }
141 | }
142 | }
143 | myDoc.select(NothingEnum.NOTHING);
144 | //alert("FERTIG! ;-) \r\rVergebene Startseiten-Label: " + myStartCounter + "\rVergebene Endseiten-Label: " + myEndCounter);
145 | }
146 | else{
147 | alert("FEHLER! \r\rEs ist kein Dokument geöffnet.");
148 | }
149 | }
150 |
151 | function checkPrevFrame(thisFrame, thisPage) {
152 | if(thisFrame.previousTextFrame != null) {
153 | var thisPrevFrame = thisFrame.previousTextFrame;
154 | // Wenn Rahmen auf Montagefläche, vorherigen überprüfen, u.s.w.
155 | while (thisPrevFrame.parentPage == null) {
156 | /* thisPrevFrame.select();
157 | app.activeWindow.zoomPercentage = app.activeWindow.zoomPercentage;
158 | alert("Rahmen auf Montagefläche!"); */
159 | if(thisPrevFrame.previousTextFrame != null) {
160 | var thisPrevFrame = thisPrevFrame.previousTextFrame;
161 | }
162 | else return true;
163 | }
164 | if (thisPrevFrame.parentPage != thisPage) return true;
165 | else return false;
166 | }
167 | else return true;
168 | }
169 |
170 |
171 | function newCondition(myDoc, myCondName) {
172 | if(checkCondition(myDoc, myCondName)) {
173 | var myCond = myDoc.conditions.item(myCondName)
174 | myCond.visible = false;
175 | // Text mit dieser Bedingung löschen ...
176 | try {
177 | var myHiddenText1 = myDoc.stories.everyItem().hiddenTexts.everyItem().texts.everyItem().getElements();
178 | }
179 | catch(e) {}
180 | if(myHiddenText1 != null){
181 | for (var i = myHiddenText1.length-1; i >= 0; i--) {
182 | // Prüfung: versteckter Text hat mindestens eine Bedingung zugewiesen
183 | if (myHiddenText1[i].appliedConditions.length > 0) {
184 | for (var x = myHiddenText1[i].appliedConditions.length-1; x >= 0; x--) {
185 | // Prüfung der dem versteckten zugewiesenen Bedingung
186 | if (myHiddenText1[i].appliedConditions[x].name == myCondName) {
187 | //alert(myHiddenText1[i].texts[0].contents);
188 | myHiddenText1[i].remove();
189 | }
190 | }
191 | }
192 | }
193 | }
194 | // How do I treat story hiddentext and cell hiddentext in a single pass? I.e., how can
195 | // I merge the two lists? concat() did not work.
196 | try {
197 | var myHiddenText = myDoc.stories.everyItem().tables.everyItem().cells.everyItem().hiddenTexts.everyItem().texts.everyItem().getElements();
198 | }
199 | catch(e) {}
200 | if(myHiddenText != null){
201 | for (var i = myHiddenText.length-1; i >= 0; i--) {
202 | if (myHiddenText[i].appliedConditions.length > 0) {
203 | for (var x = myHiddenText[i].appliedConditions.length-1; x >= 0; x--) {
204 | if (myHiddenText[i].appliedConditions[x].name == myCondName) {
205 | myHiddenText[i].remove();
206 | }
207 | }
208 | }
209 | }
210 | }
211 | }
212 | else{
213 | var myCond = myDoc.conditions.add({name:myCondName, visible:false});
214 | }
215 | return myCond;
216 | }
217 |
218 | function checkCondition(myDoc, myConditionName) {
219 | try {
220 | var myCond = myDoc.conditions.item(myConditionName);
221 | myCond.name;
222 | return true;
223 | }
224 | catch(e) {
225 | return false;
226 | }
227 | }
228 |
229 | function checkConditionSet(myDoc, myConditionSetName) {
230 | try {
231 | var myCondSet = myDoc.conditionSets.item(myConditionSetName);
232 | myCondSet.name;
233 | //alert(myConditionSetName + " gibt's schon!");
234 | return true;
235 | }
236 | catch(e) {
237 | return false;
238 | }
239 | }
240 |
241 | function checkSwatch(myDoc, mySwatchName) {
242 | try {
243 | myTestSwatch = myDoc.swatches.itemByName(mySwatchName);
244 | myTestSwatch.name;
245 | return true;
246 | }
247 | catch(e) {
248 | return false;
249 | }
250 | }
251 |
--------------------------------------------------------------------------------
/pagenames/PageNamesToStory_ConditionalText.jsx:
--------------------------------------------------------------------------------
1 | #target indesign
2 |
3 | //
4 | // PageNamesToStoryRevolution.jsx
5 | // Version 1.1
6 | //
7 | // created by: maqui | 10:18 28.02.2013
8 | // modified by: maqui | 16:59 28.02.2013 (Löschen der Bedingungstexte ohne Einblenden --> Formatierung bleibt 1:1 erhalten)
9 | //
10 | // Erstellt auf jedem Seitenbeginn und jedem Seitenende bedingten Text mit der jeweiligen Seitenzahl
11 | //
12 | //
13 |
14 | var myPageStartTag = "PageStart";
15 | var myPageEndTag = "PageEnd";
16 |
17 | var myStartSwatchName = "PageStart";
18 | var myEndSwatchName = "PageEnd";
19 |
20 | var myCondSetOnName = "PageNumber_On";
21 | var myCondSetOffName = "PageNumber_Off";
22 |
23 | main(); // ==>
24 |
25 | function main(){
26 | var myDoc = app.documents[0];
27 | var myPage;
28 | var mainStory = determineMainStory(myDoc); // ==>
29 |
30 | // Bedingungen definieren
31 | var myStartCond = newCondition(myDoc, myPageStartTag); // ==>
32 | var myEndCond = newCondition(myDoc, myPageEndTag); // ==>
33 |
34 | // Sets definieren
35 | if(checkConditionSet(myDoc, myCondSetOnName)) myDoc.conditionSets.item(myCondSetOnName).remove();
36 | if(checkConditionSet(myDoc, myCondSetOffName)) myDoc.conditionSets.item(myCondSetOffName).remove();
37 | var myOnSettingArray = [[myStartCond, true], [myEndCond, true]];
38 | var myOffSettingArray = [[myStartCond, false], [myEndCond, false]];
39 | var myCondSetOn = myDoc.conditionSets.add({name:myCondSetOnName, setConditions:myOnSettingArray});
40 | var myCondSetOff = myDoc.conditionSets.add({name:myCondSetOffName, setConditions:myOffSettingArray});
41 | myDoc.conditionalTextPreferences.properties = {activeConditionSet:myCondSetOn};
42 | myCondSetOn.redefine();
43 | myDoc.conditionalTextPreferences.properties = {activeConditionSet:myCondSetOff};
44 | myCondSetOff.redefine();
45 |
46 | // Farben für bedingten Text (als Orientierungshilfe)
47 | if (checkSwatch(myDoc, myStartSwatchName) == false) myDoc.colors.add({name:myStartSwatchName, colorValue:[0,0,255], model:ColorModel.PROCESS, space:ColorSpace.RGB});
48 | if (checkSwatch(myDoc, myEndSwatchName) == false) myDoc.colors.add({name:myEndSwatchName, colorValue:[255,0,0], model:ColorModel.PROCESS, space:ColorSpace.RGB});
49 | var myStartSwatch = myDoc.swatches.itemByName(myStartSwatchName);
50 | var myEndSwatch = myDoc.swatches.itemByName(myEndSwatchName);
51 |
52 | // Alle Textrahmen vom Hauptext durchlaufen
53 | var myFrame = mainStory.textContainers[mainStory.textContainers.length-1];
54 | var myOldPage;
55 | while (myFrame != null) {
56 | var myPage = myFrame.parentPage;
57 | if(myFrame.constructor.name == "TextFrame" && myPage != null && myFrame.insertionPoints.length > 0) {
58 | // PageEnd
59 | // Ist Rahmen auf anderer Seite? ... Wenn ja, dann PageEnd-Tag setzen
60 | if(myPage != myOldPage) {
61 | var myLastContent = myPageEndTag + "_" + myPage.name;
62 | if(myOldFirstIP) {
63 | //var myLastIP = myOldFirstIP.parentStory.insertionPoints.previousItem(myOldFirstIP);
64 | var myLastIP = myOldFirstIP.parentStory.insertionPoints[myOldID - 1];
65 | //var myLastID = myLastIP.parentStory.insertionPoints.itemByRange(0, myLastIP.index).insertionPoints.length;
66 | //alert(myOldID + "\n" + myLastID);
67 | }
68 | else {
69 | var myLastIP = myFrame.insertionPoints.lastItem();
70 | }
71 | myLastIP.contents = myLastContent;
72 | myLastIP.fillColor = myEndSwatch;
73 | myLastIP.applyConditions(myEndCond, true);
74 | }
75 | // PageStart
76 | // Ist vorheriger Rahmen auf anderer Seite? ... Wenn ja, dann PageStart-Tag setzen
77 | if (checkPrevFrame(myFrame, myPage)) {
78 | var myFirstContent = myPageStartTag + "_" + myPage.name;
79 | var myFirstIP = myFrame.insertionPoints.firstItem();
80 | var myOldFirstIP = myFirstIP; // IP merken, da er sich bei evtl. Umbruchveränderungen verschiebt
81 | var myOldID = myOldFirstIP.parentStory.insertionPoints.itemByRange(0, myOldFirstIP.index).insertionPoints.length;
82 | myFirstIP.contents = myFirstContent;
83 | myFirstIP.fillColor = myStartSwatch;
84 | myFirstIP.applyConditions(myStartCond, true);
85 | }
86 | myOldPage = myPage;
87 | }
88 | var myFrame = myFrame.previousTextFrame;
89 | }
90 | myDoc.select(NothingEnum.NOTHING);
91 | }
92 |
93 | function checkPrevFrame(thisFrame, thisPage) {
94 | if(thisFrame.previousTextFrame != null) {
95 | var thisPrevFrame = thisFrame.previousTextFrame;
96 | // Wenn Rahmen auf Montagefläche, vorherigen überprüfen, u.s.w.
97 | while (thisPrevFrame.parentPage == null) {
98 | /* thisPrevFrame.select();
99 | app.activeWindow.zoomPercentage = app.activeWindow.zoomPercentage;
100 | alert("Rahmen auf Montagefläche!"); */
101 | if(thisPrevFrame.previousTextFrame != null) {
102 | var thisPrevFrame = thisPrevFrame.previousTextFrame;
103 | }
104 | else return true;
105 | }
106 | if (thisPrevFrame.parentPage != thisPage) return true;
107 | else return false;
108 | }
109 | else return true;
110 | }
111 |
112 |
113 | // Pick the story that is parent story to the largest number of text frames:
114 | function determineMainStory(doc) {
115 | var textFrameCount = new Object;
116 | var max = 0;
117 | var mainStory = false;
118 | for (var p = 1; p <= doc.pages.length; p++) {
119 | page = doc.pages[p-1];
120 | for (var t = 0; t < page.textFrames.length; t++) {
121 | if(mainStory == false) mainStory = page.textFrames[t].parentStory;
122 | var key = String(page.textFrames[t].parentStory.id);
123 | if (textFrameCount[key] == null) {
124 | textFrameCount[key] = 1;
125 | } else {
126 | textFrameCount[key] += 1;
127 | if (textFrameCount[key] > max) {
128 | max = textFrameCount[key];
129 | mainStory = page.textFrames[t].parentStory;
130 | }
131 | }
132 | }
133 | }
134 | return mainStory;
135 | }
136 |
137 | function newCondition(myDoc, myCondName) {
138 | if(checkCondition(myDoc, myCondName)) {
139 | var myCond = myDoc.conditions.item(myCondName)
140 | // Text mit dieser Bedingung löschen ...
141 | try {
142 | var myHiddenText = myDoc.stories.everyItem().hiddenTexts.everyItem().texts.everyItem().getElements();
143 | }
144 | catch(e) {}
145 | if(myHiddenText){
146 | for (var i = myHiddenText.length-1; i >= 0; i--) {
147 | // Prüfung: versteckter Text hat mindestens eine Bedingung zugewiesen
148 | if (myHiddenText[i].appliedConditions.length > 0) {
149 | for (var x = myHiddenText[i].appliedConditions.length-1; x >= 0; x--) {
150 | // Prüfung der dem versteckten zugewiesenen Bedingung
151 | if (myHiddenText[i].appliedConditions[x].name == myCondName) {
152 | //alert(myHiddenText[i].texts[0].contents);
153 | myHiddenText[i].remove();
154 | }
155 | }
156 | }
157 | }
158 | }
159 | }
160 | else{
161 | var myCond = myDoc.conditions.add({name:myCondName, visible:false});
162 | }
163 | return myCond;
164 | }
165 |
166 | function checkCondition(myDoc, myConditionName) {
167 | try {
168 | var myCond = myDoc.conditions.item(myConditionName);
169 | myCond.name;
170 | return true;
171 | }
172 | catch(e) {
173 | return false;
174 | }
175 | }
176 |
177 | function checkConditionSet(myDoc, myConditionSetName) {
178 | try {
179 | var myCondSet = myDoc.conditionSets.item(myConditionSetName);
180 | myCondSet.name;
181 | //alert(myConditionSetName + " gibt's schon!");
182 | return true;
183 | }
184 | catch(e) {
185 | return false;
186 | }
187 | }
188 |
189 | function checkSwatch(myDoc, mySwatchName) {
190 | try {
191 | myTestSwatch = myDoc.swatches.itemByName(mySwatchName);
192 | myTestSwatch.name;
193 | return true;
194 | }
195 | catch(e) {
196 | return false;
197 | }
198 | }
199 |
--------------------------------------------------------------------------------
/pagenames/PageNamesToStory_Notes.jsx:
--------------------------------------------------------------------------------
1 | #target indesign
2 |
3 | //
4 | // PageNamesToStory_Notes.jsx
5 | // Version 1.3
6 | //
7 | // created by: maqui | 10:18 28.02.2013
8 | // modified by: maqui | 16:59 28.02.2013 (Löschen der Bedingungstexte ohne Einblenden --> Formatierung bleibt 1:1 erhalten)
9 | // modified by: maqui | 16:40 16.06.2014 Alle Textabschnitte erhalten die Seitenzahl-Infos
10 | // modified by: maqui | 11:00 21.05.2015 Debug (bedingten Text "PageStart" und "PageEnd" löschen, auch wenn er sichtbar ist)
11 | // modified by: gimsieke | 2015-06-07 Add 'CellPage_XY' to table cells
12 | // modified by: aschmalfuss | 2018-02-26 replace conditional text with notes
13 | //
14 | // Trägt in jedem Textrahmen (bei jedem Seitenwechsel) den Seitenbeginn bzw. das Seitenende als Notiz mit der jeweiligen Seitenzahl ein.
15 | //
16 | //
17 |
18 | var myPageStartTag = "PageStart";
19 | var myPageEndTag = "PageEnd";
20 |
21 | //var myStartSwatchName = "PageStart";
22 | //var myEndSwatchName = "PageEnd";
23 |
24 | main(); // ==>
25 |
26 | function main(){
27 | if(app.documents.length != 0){
28 | var myDoc = app.activeDocument;
29 | var myPage;
30 |
31 | var myStartCounter = 0;
32 | var myEndCounter = 0;
33 | for (var i = 0; i < myDoc.stories.length; i++) {
34 | var myStory = myDoc.stories[i];
35 | myStory.notes.everyItem().remove();
36 | var myMasterSpreadFlag = true;
37 | for (var j = 0; j < myStory.textContainers.length; j++) {
38 | var myTestFrame = myStory.textContainers[j];
39 | // Wenn ein Textrahmen nicht auf der Montagefläche ...
40 | if(myTestFrame.hasOwnProperty("parentPage") && myTestFrame.parentPage != null) {
41 | // ... überprüfen, ob auf Musterseite
42 | if(myTestFrame.parentPage.parent.constructor.name != "MasterSpread" && myStory.textContainers.length > 0) {
43 | myMasterSpreadFlag = false;
44 | break;
45 | }
46 | }
47 | }
48 | // Wenn Textabschnitt sich nicht auf einer Musterseite befindet, ...
49 | if(!myMasterSpreadFlag && myStory.textContainers.length > 0) {
50 | // Alle Textrahmen vom Textabschnitt durchlaufen ...
51 | var myFrame = myStory.textContainers[myStory.textContainers.length - 1];
52 | var myOldPage = false; // wenn nicht als "false" definiert, ist myOldPage letzter "Page"-Wert???????????????????????
53 | var myOldFirstIP = false;
54 | while (myFrame != null) {
55 | var myPage = myFrame.parentPage;
56 | // Wenn Textabschnitt sich nicht auf Montagefläche ...
57 | if(myPage != null && (myFrame.constructor.name == "TextFrame"
58 | || myFrame.constructor.name == "EndnoteTextFrame") && myFrame.insertionPoints.length > 0) {
59 | // PageEnd
60 | // Ist Rahmen auf anderer Seite? ... Wenn ja, dann PageEnd-Tag setzen
61 | if(myPage != myOldPage) {
62 | var myLastContent = myPageEndTag + "_" + myPage.name;
63 | if(myOldFirstIP) {
64 | //var myLastIP = myOldFirstIP.parentStory.insertionPoints.previousItem(myOldFirstIP);
65 | var myLastIP = myOldFirstIP.parentStory.insertionPoints[myOldID - 1];
66 | //var myLastID = myLastIP.parentStory.insertionPoints.itemByRange(0, myLastIP.index).insertionPoints.length;
67 | //alert(myOldID + "\n" + myLastID);
68 | }
69 | else {
70 | var myLastIP = myFrame.insertionPoints.lastItem();
71 | //myFrame.select();
72 | //app.activeWindow.zoomPercentage = app.activeWindow.zoomPercentage;
73 | //alert(myLastContent + " :: " + myOldPage.constructor.name);
74 | }
75 | //myLastIP.fillColor = myEndSwatch;
76 | var note = myLastIP.notes.add();
77 | note.label=myPageEndTag;
78 | note.texts[0].contents=myLastContent;
79 | myEndCounter++;
80 | }
81 | // PageStart
82 | // Ist vorheriger Rahmen auf anderer Seite? ... Wenn ja, dann PageStart-Tag setzen
83 | if (checkPrevFrame(myFrame, myPage) && myFrame.contents != "") {
84 | var myFirstContent = myPageStartTag + "_" + myPage.name;
85 | var myFirstIP = myFrame.insertionPoints.firstItem();
86 | var myOldFirstIP = myFirstIP; // IP merken, da er sich bei evtl. Umbruchveränderungen verschiebt
87 | var myOldID = myOldFirstIP.parentStory.insertionPoints.itemByRange(0, myOldFirstIP.index).insertionPoints.length;
88 | var note = myFirstIP.notes.add();
89 | note.label=myPageStartTag;
90 | note.texts[0].contents=myFirstContent;
91 | myStartCounter++;
92 | }
93 | myOldPage = myPage;
94 | }
95 | var myFrame = myFrame.previousTextFrame;
96 | }
97 | }
98 |
99 | // Process all table cells in the story since they won't be included in the frame iteration:
100 | if(!myMasterSpreadFlag && myStory.tables.length > 0) {
101 | for (var t = 0; t < myStory.tables.length; t++) {
102 | myStory.tables[t].notes.everyItem().remove();
103 | for (var c = 0; c < myStory.tables[t].cells.length; c++) {
104 | var myCell = myStory.tables[t].cells[c];
105 | var firstCellChar = myCell.characters[0];
106 | if (firstCellChar != null) {
107 | var myFrame = firstCellChar.parentTextFrames[0];
108 | if (myFrame != null) {
109 | var myPage = myFrame.parentPage;
110 | var myIP = myCell.insertionPoints.firstItem();
111 | //myIP.fillColor = myStartSwatch;
112 | var note = myIP.notes.add();
113 | note.label="PageName";
114 | note.texts[0].contents="CellPage_" + myPage.name;
115 | }
116 | }
117 | }
118 | }
119 | }
120 | }
121 | myDoc.select(NothingEnum.NOTHING);
122 | //alert("FERTIG! ;-) \r\rVergebene Startseiten-Label: " + myStartCounter + "\rVergebene Endseiten-Label: " + myEndCounter);
123 | }
124 | else{
125 | alert("FEHLER! \r\rEs ist kein Dokument geöffnet.");
126 | }
127 | }
128 |
129 | function checkPrevFrame(thisFrame, thisPage) {
130 | if(thisFrame.previousTextFrame != null) {
131 | var thisPrevFrame = thisFrame.previousTextFrame;
132 | // Wenn Rahmen auf Montagefläche, vorherigen überprüfen, u.s.w.
133 | while (thisPrevFrame.parentPage == null) {
134 | /* thisPrevFrame.select();
135 | app.activeWindow.zoomPercentage = app.activeWindow.zoomPercentage;
136 | alert("Rahmen auf Montagefläche!"); */
137 | if(thisPrevFrame.previousTextFrame != null) {
138 | var thisPrevFrame = thisPrevFrame.previousTextFrame;
139 | }
140 | else return true;
141 | }
142 | if (thisPrevFrame.parentPage != thisPage) return true;
143 | else return false;
144 | }
145 | else return true;
146 | }
147 |
148 |
--------------------------------------------------------------------------------
/pagenames/PageNamesToStory_Notes_Book.jsx:
--------------------------------------------------------------------------------
1 | #target indesign
2 |
3 | //
4 | // PageNamesToStory_Notes.jsx
5 | // Version 1.3
6 | //
7 | // created by: maqui | 10:18 28.02.2013
8 | // modified by: maqui | 16:59 28.02.2013 (Löschen der Bedingungstexte ohne Einblenden --> Formatierung bleibt 1:1 erhalten)
9 | // modified by: maqui | 16:40 16.06.2014 Alle Textabschnitte erhalten die Seitenzahl-Infos
10 | // modified by: maqui | 11:00 21.05.2015 Debug (bedingten Text "PageStart" und "PageEnd" löschen, auch wenn er sichtbar ist)
11 | // modified by: gimsieke | 2015-06-07 Add 'CellPage_XY' to table cells
12 | // modified by: aschmalfuss | 2018-02-26 replace conditional text with notes
13 | //
14 | // Trägt in jedem Textrahmen (bei jedem Seitenwechsel) den Seitenbeginn bzw. das Seitenende als Notiz mit der jeweiligen Seitenzahl ein.
15 | //
16 | //
17 |
18 | var myPageStartTag = "PageStart";
19 | var myPageEndTag = "PageEnd";
20 |
21 | //var myStartSwatchName = "PageStart";
22 | //var myEndSwatchName = "PageEnd";
23 |
24 | main(); // ==>
25 |
26 | function main(){
27 | if(app.documents.length != 0){
28 | var book = app.books.item(get_book());
29 | var docs = book.bookContents.everyItem().fullName;
30 | var myPage;
31 |
32 | var myStartCounter = 0;
33 | var myEndCounter = 0;
34 | for (var k = 0; k < docs.length; k++) {
35 | var doc = app.open(docs[k], true);
36 | for (var i = 0; i < doc.stories.length; i++) {
37 | var myStory = doc.stories[i];
38 | myStory.notes.everyItem().remove();
39 | var myMasterSpreadFlag = true;
40 | for (var j = 0; j < myStory.textContainers.length; j++) {
41 | var myTestFrame = myStory.textContainers[j];
42 | // Wenn ein Textrahmen nicht auf der Montagefläche ...
43 | if(myTestFrame.hasOwnProperty("parentPage") && myTestFrame.parentPage != null) {
44 | // ... überprüfen, ob auf Musterseite
45 | if(myTestFrame.parentPage.parent.constructor.name != "MasterSpread" && myStory.textContainers.length > 0) {
46 | myMasterSpreadFlag = false;
47 | break;
48 | }
49 | }
50 | }
51 | // Wenn Textabschnitt sich nicht auf einer Musterseite befindet, ...
52 | if(!myMasterSpreadFlag && myStory.textContainers.length > 0) {
53 | // Alle Textrahmen vom Textabschnitt durchlaufen ...
54 | var myFrame = myStory.textContainers[myStory.textContainers.length - 1];
55 | var myOldPage = false; // wenn nicht als "false" definiert, ist myOldPage letzter "Page"-Wert???????????????????????
56 | var myOldFirstIP = false;
57 | while (myFrame != null) {
58 | var myPage = myFrame.parentPage;
59 | // Wenn Textabschnitt sich nicht auf Montagefläche ...
60 | if(myPage != null && (myFrame.constructor.name == "TextFrame"
61 | || myFrame.constructor.name == "EndnoteTextFrame") && myFrame.insertionPoints.length > 0) {
62 | // PageEnd
63 | // Ist Rahmen auf anderer Seite? ... Wenn ja, dann PageEnd-Tag setzen
64 | if(myPage != myOldPage) {
65 | var myLastContent = myPageEndTag + "_" + myPage.name;
66 | if(myOldFirstIP) {
67 | //var myLastIP = myOldFirstIP.parentStory.insertionPoints.previousItem(myOldFirstIP);
68 | var myLastIP = myOldFirstIP.parentStory.insertionPoints[myOldID - 1];
69 | //var myLastID = myLastIP.parentStory.insertionPoints.itemByRange(0, myLastIP.index).insertionPoints.length;
70 | //alert(myOldID + "\n" + myLastID);
71 | }
72 | else {
73 | var myLastIP = myFrame.insertionPoints.lastItem();
74 | //myFrame.select();
75 | //app.activeWindow.zoomPercentage = app.activeWindow.zoomPercentage;
76 | //alert(myLastContent + " :: " + myOldPage.constructor.name);
77 | }
78 | //myLastIP.fillColor = myEndSwatch;
79 | var note = myLastIP.notes.add();
80 | note.label=myPageEndTag;
81 | note.texts[0].contents=myLastContent;
82 | myEndCounter++;
83 | }
84 | // PageStart
85 | // Ist vorheriger Rahmen auf anderer Seite? ... Wenn ja, dann PageStart-Tag setzen
86 | if (checkPrevFrame(myFrame, myPage) && myFrame.contents != "") {
87 | var myFirstContent = myPageStartTag + "_" + myPage.name;
88 | var myFirstIP = myFrame.insertionPoints.firstItem();
89 | var myOldFirstIP = myFirstIP; // IP merken, da er sich bei evtl. Umbruchveränderungen verschiebt
90 | var myOldID = myOldFirstIP.parentStory.insertionPoints.itemByRange(0, myOldFirstIP.index).insertionPoints.length;
91 | var note = myFirstIP.notes.add();
92 | note.label=myPageStartTag;
93 | note.texts[0].contents=myFirstContent;
94 | myStartCounter++;
95 | }
96 | myOldPage = myPage;
97 | }
98 | var myFrame = myFrame.previousTextFrame;
99 | }
100 | }
101 |
102 | // Process all table cells in the story since they won't be included in the frame iteration:
103 | if(!myMasterSpreadFlag && myStory.tables.length > 0) {
104 | for (var t = 0; t < myStory.tables.length; t++) {
105 | myStory.tables[t].notes.everyItem().remove();
106 | for (var c = 0; c < myStory.tables[t].cells.length; c++) {
107 | var myCell = myStory.tables[t].cells[c];
108 | var firstCellChar = myCell.characters[0];
109 | if (firstCellChar != null) {
110 | var myFrame = firstCellChar.parentTextFrames[0];
111 | if (myFrame != null) {
112 | var myPage = myFrame.parentPage;
113 | var myIP = myCell.insertionPoints.firstItem();
114 | //myIP.fillColor = myStartSwatch;
115 | var note = myIP.notes.add();
116 | note.label="PageName";
117 | note.texts[0].contents="CellPage_" + myPage.name;
118 | }
119 | }
120 | }
121 | }
122 | }
123 | }
124 | doc.select(NothingEnum.NOTHING);
125 | doc.save();
126 | $.sleep(200); // 0,2 Sekunden warten
127 | doc.close();
128 | }
129 |
130 | }
131 | }
132 |
133 | function checkPrevFrame(thisFrame, thisPage) {
134 | if(thisFrame.previousTextFrame != null) {
135 | var thisPrevFrame = thisFrame.previousTextFrame;
136 | // Wenn Rahmen auf Montagefläche, vorherigen überprüfen, u.s.w.
137 | while (thisPrevFrame.parentPage == null) {
138 | /* thisPrevFrame.select();
139 | app.activeWindow.zoomPercentage = app.activeWindow.zoomPercentage;
140 | alert("Rahmen auf Montagefläche!"); */
141 | if(thisPrevFrame.previousTextFrame != null) {
142 | var thisPrevFrame = thisPrevFrame.previousTextFrame;
143 | }
144 | else return true;
145 | }
146 | if (thisPrevFrame.parentPage != thisPage) return true;
147 | else return false;
148 | }
149 | else return true;
150 | }
151 |
152 | function get_book ()
153 | {
154 | switch (app.books.length)
155 | {
156 | case 0: alert ("FEHLER! \r\rKeine Buch-Datei geöffnet!"); exit ();
157 | case 1: return app.books[0].name;
158 | default: return pick_book ();
159 | }
160 | }
161 |
162 |
163 | function pick_book ()
164 | {
165 | var w = new Window ("dialog", "Buch-Datei auswählen");
166 | w.alignChildren = "right";
167 | var g = w.add ("group");
168 | var list = g.add ("listbox", undefined, app.books.everyItem().name);
169 | list.minimumSize.width = 250;
170 | list.selection = 0;
171 | var b = w.add ("group");
172 | b.add ("button", undefined, "OK", {name: "ok"})
173 | b.add ("button", undefined, "Abbrechen", {name: "cancel"})
174 | if (w.show () == 1)
175 | return list.selection.text;
176 | else
177 | exit ();
178 | }
179 |
180 |
181 |
182 |
--------------------------------------------------------------------------------
/pagenames/README.md:
--------------------------------------------------------------------------------
1 | __[PageNamesToStory_ConditionalText.jsx](pagenames/PageNamesToStory_ConditionalText.jsx)__
2 |
3 | Will first identify the story that runs through the highest number of pages (called `mainStory` in the script).
4 |
5 | Will then add conditional text to the beginning and end of each page in mainStory:
6 |
7 | * Condition: PageStart. Text: 'PageStart_[name]'.
8 | * Condition: PageEnd. Text: 'PageEnd_[name]'.
9 |
10 | This information may then be processed by a converter that works on an IDML export, since it will otherwise not know on which page which content is placed.
11 |
12 | Will remove existing PageStart/PageEnd conditional text before inserting new PageStart/PageEnd conditional text.
13 |
14 | In order to get accurate information, make sure to process the document with all relevant fonts installed so that the pagination is the same.
15 |
16 | If there are any objects between a PageEnd and the subsequent PageStart label, a processor will not know on which page they are exactly. It might therefore be important to anchor tables or figures with captions before the last mainStory character on a page, because otherwise the PageEnd label might be inserted before the anchor.
17 |
18 | This script will not work well for documents that don’t have a main story, i.e., where text does not flow from frame to frame across the pages or where each chapter is a story of its own. There will be another version or an option to better support these use cases.
19 |
--------------------------------------------------------------------------------
/paragraph-textDestinations/README.md:
--------------------------------------------------------------------------------
1 | # insertTextDestinations.jsx
2 |
3 | An InDesign script that adds text destinations to the start of each paragraph.
4 |
5 | It skips empty paragraphs.
6 |
7 | Paragraphs that already contain a text destination at its start will also be skipped.
8 |
--------------------------------------------------------------------------------
/paragraph-textDestinations/insertTextDestinations.jsx:
--------------------------------------------------------------------------------
1 | #target indesign
2 |
3 | //insertTextDestinations.jsx
4 | //author: Anna Schmalfuß, le-tex publishing services GmbH
5 | //version: 1.0
6 | //date: 2016-05-31
7 |
8 | //checks for pre-existing text destinations
9 | //creates a text destination at the beginning of each paragraph
10 |
11 | var counter = 0;
12 |
13 | if(app.documents.length != 0) {
14 | var doc = app.activeDocument;
15 | var progress = new Window('palette', localize("Creating text destinations") );
16 | progress.frameLocation = [400,275];
17 | progress.bar = progress.add('progressbar');
18 | progress.bar.size = [400,15];
19 | progress.bar.value = 0;
20 | progress.bar.maxvalue = doc.stories.length;
21 | progress.file = progress.add('statictext');
22 | progress.file.size = [400,15];
23 | progress.show();
24 | for(var i = 0; i < doc.stories.length; i++){
25 | progress.bar.value++;
26 | progress.file.text = "Story " + i + "/" + doc.stories.length;
27 |
28 | var story = doc.stories[i];
29 | counter = insertTextDest(story, i, counter);
30 | }
31 | progress.close();
32 | alert("Number of created text destinations: " + counter);
33 |
34 | }
35 |
36 | else{
37 | alert("Error! \r\rNo active document!");
38 | }
39 |
40 |
41 |
42 | // ********************** functions **********************
43 |
44 | function insertTextDest(text, storyID, destCount){
45 | var lengths = text.paragraphs.everyItem().length;
46 | for (var j = lengths.length - 1; j >= 0; j--) {
47 | var para = text.paragraphs[j];
48 | if (lengths[j] != 1 && checkForDest(para, storyID)) {
49 | try{
50 | var name = String(Math.random()).substr(2, 7) + lengths[j] + storyID;
51 | name = name.slice(-8);
52 | doc.hyperlinkTextDestinations.add(para.insertionPoints[0], {name: name + "_" + storyID});
53 | destCount ++;
54 | }
55 | catch(e){
56 | var zoom = app.activeWindow.zoomPercentage;
57 | app.activeWindow.zoomPercentage = zoom;
58 | alert(e);
59 | }
60 | }
61 | }
62 | return destCount;
63 | }
64 |
65 |
66 | function checkForDest(para, storyID){
67 | var check = true;
68 | for (var k = doc.hyperlinkTextDestinations.length - 1; k >= 0; k--) {
69 | var dest = doc.hyperlinkTextDestinations[k];
70 | if(dest.destinationText.index == para.insertionPoints[0].index && dest.name.match("_" + storyID)) check = false
71 | }
72 | return check;
73 | }
--------------------------------------------------------------------------------
/text-to-image/README.md:
--------------------------------------------------------------------------------
1 | # ReplaceSelectedTextAsImage.jsx
2 |
3 | A very simple script to save the selected text as an image and replace the text with it.
4 |
5 | With an option to navigate the cursor to the next/first content with character style in style group '~~~~~(MathTools)' (see variable searchNextMathToolsFormat).
--------------------------------------------------------------------------------
/text-to-image/ReplaceSelectedTextAsImage.jsx:
--------------------------------------------------------------------------------
1 | #target indesign
2 | // ReplaceSelectedTextAsImage.jsx
3 | // written by Philipp Glatza, le-tex publishing services GmbH
4 | // version 0.9.7 (2024-09-25)
5 | // - truncated chars fix: turn off auto-resize for the textframe before export and add extra (white)space to the right
6 | // version 0.9.6 (2024-05-30)
7 | // - exclude last char if selected: CR (U+0013)
8 | // version 0.9.5 (2022-09-13)
9 | // - apply 'None' object style to created Rectangle
10 | // version 0.9.4 (2022-09-07)
11 | // - remove the created textframe, if not already removed
12 | // version 0.9.3 (2021-01-18)
13 | // - remove any list number/label from paragraph
14 | // version 0.9.2 (2020-12-15)
15 | // - better support for text in table cells
16 | // version 0.9.1 (2020-06-10)
17 | // - anchor exported image inline with better size and fit options
18 | // version 0.9 (2019-11-27)
19 |
20 | // user variables
21 | var strImageFilenamePrefix = "img_p"
22 | var searchNextMathToolsFormat = false; // values: true or false: when 'true', jump to next MathTools markup
23 |
24 |
25 | // functions
26 |
27 | myDoc = app.activeDocument;
28 | selection = app.selection[0];
29 | if(selection && selection.length) {
30 | // last char is a paragraph break
31 | if(selection.contents.charCodeAt(selection.length -1 ) == 13 ) {
32 | selection.insertionPoints.itemByRange(0, -2).select()
33 | selection = app.selection[0];
34 | }
35 | var myTf = selection.insertionPoints.lastItem().textFrames.add({geometricBounds:[0, 0, 1, 1 ]});
36 | var d = new Date(),
37 | random = Math.floor(Math.random()*Math.floor(d / 1000)),
38 | strFilename = strImageFilenamePrefix + selection.parentTextFrames[0].parentPage.name + '_' + random + '.png'
39 | intStartPosNormalized = 0
40 | intEndPosNormalized = -1;
41 | if(selection.insertionPoints.itemByRange(0, 1).contents.toString().match(/^\s/g)) {
42 | intStartPosNormalized = 1;
43 | }
44 | if(selection.insertionPoints.itemByRange(-2, -1).contents.toString().match(/\s$/g)) {
45 | intEndPosNormalized = -2;
46 | }
47 | selection.insertionPoints.itemByRange(intStartPosNormalized, intEndPosNormalized).select()
48 | selection = app.selection[0];
49 | selection.duplicate(LocationOptions.AT_BEGINNING, myTf.insertionPoints.item(0));
50 | for(p = 0, ps = myTf.paragraphs.length; p < ps; p++) {
51 | myTf.paragraphs[p].bulletsAndNumberingListType = ListType.NO_LIST
52 | myTf.paragraphs[p].firstLineIndent = 0
53 | myTf.paragraphs[p].leftIndent = 0
54 | myTf.paragraphs[p].lastLineIndent = 0
55 | }
56 | myTf.textFramePreferences.useNoLineBreaksForAutoSizing = true
57 | myTf.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_AND_WIDTH
58 | myTf.fit (FitOptions.FRAME_TO_CONTENT);
59 | var myBounds = myTf.geometricBounds,
60 | myRect = null;
61 | myTf.textFramePreferences.autoSizingType = AutoSizingTypeEnum.OFF
62 | myTf.geometricBounds = new Array(myBounds[0],myBounds[1],myBounds[2],myBounds[3] + 1.5)
63 | myTf.exportFile(ExportFormat.PNG_FORMAT, File(Folder.myDocuments+'/' + strFilename))
64 | // text in table cell
65 | if(selection.parent.name.search("^[0-9]+:[0-9]+$") == 0) {
66 | var cwidth = selection.parent.width;
67 | myRect = selection.insertionPoints[0].rectangles.add();
68 | myRect.place (File(Folder.myDocuments+'/' + strFilename));
69 | selection.parent.width = cwidth;
70 | } else {
71 | myRect = selection.insertionPoints[0].rectangles.add( {geometricBounds:[0,0, 10, 10 ]});
72 | myRect.place (File(Folder.myDocuments+'/' + strFilename));
73 | myRect.geometricBounds = myBounds;
74 | }
75 | myRect.applyObjectStyle(app.activeDocument.objectStyles.itemByName('$ID/[None]'))
76 | myRect.fit(FitOptions.CONTENT_TO_FRAME);
77 | myRect.anchoredObjectSettings.anchoredPosition = AnchorPosition.INLINE_POSITION;
78 | myRect.anchoredObjectSettings.anchorYoffset = 0;
79 | selection.remove()
80 | try{myTf.remove()}catch(e){}
81 |
82 | // search next MathTools cstyle
83 | if(searchNextMathToolsFormat) {
84 | MathToolsStyles = myDoc.characterStyleGroups.itemByName("~~~~~(MathTools)").characterStyles
85 | for(i = 0, j = MathToolsStyles.length; i 0) {
150 | for (var k = foundItems.length - 1; k >= 0; k--) {
151 | if(foundItems[k].appliedConditions.length != 0) {
152 | var myItem = foundItems[k];
153 | myFoundArray.push(myItem);
154 | var myPage = foundItems[k].parentTextFrames[0].parentPage;
155 | var myLine = foundItems[k].insertionPoints[0].lines[0];
156 | var myItemText = "S. " + myPage.name + ":\t[...]" + myLine.contents;
157 | myText += myItemText + "\n";
158 | } // if
159 | x.pbar.value = x.pbar.value + 1;
160 | } // for
161 | } // if
162 | for (var j = 0; j < myFoundArray.length; j++) {
163 | myFoundArray[j].appliedConditions = [];
164 | } // for
165 | //Log-Datei schreiben
166 |
167 | if (myText.length > 71) { // entspricht Mindestlänge vpn befüllter Textdatei
168 | var logName = "/PreExportCeck_bedingte-Texte.txt";
169 | saveAs(myText , logName);
170 | alert("Es wurden bedingte Texte von Absatzmarken gelöscht. \n\nEine Liste aller geänderten Textstellen finden sie unter\n" + myFile + logName)
171 | } // if
172 | else {
173 | alert("Prüfung der bedingten Texte beendet: \nAlles in Ordnung!");
174 | }
175 | } // function
176 |
177 |
178 | // --------------------------------------------------------------------------
179 |
180 | function askForExport() {
181 | var confi = confirm("Soll die Datei exportiert werden?");
182 | if (confi) {
183 | exportIdml()
184 | } // if
185 | else {
186 | // Bedingungen wieder ein- bzw. ausblenden wie vor Export
187 | for (var i = 0; i < myConditions.length; i++) {
188 | var visible = conditionArray[i]
189 | myConditions[i].visible = visible
190 | } // for
191 | } // else
192 | } // function
193 |
194 |
195 | // --------------------------------------------------------------------------
196 |
197 | function checkStyles() {
198 |
199 | var allMissingParaStyles = [];
200 | var allMissingCharStyles = [];
201 | var allMissingTableStyles = [];
202 | var allMissingCellStyles = [];
203 | var allMissingObjStyles = [];
204 |
205 |
206 | var myScriptFile = myGetScriptPath();
207 | var end = myScriptFile.lastIndexOf("/");
208 | var myScriptString = myScriptFile.slice(0, end + 1);
209 | var myXMLFile = File(myScriptString + "cssa.xml");
210 | if (!myXMLFile.exists) {
211 | alert(myScriptString + "cssa.xml " + " \nkonnte nicht gefunden werden.");
212 | myScriptFile = File(myScriptFile);
213 | myXMLFile = myScriptFile.openDlg("Bitte wählen Sie die cssa.xml aus:", ["Xml-Dateien:*.xml", "Alle Dateien:*.*"])
214 | } // if
215 |
216 | if (myXMLFile != null) {
217 | var myXMLRoot = loadJS(myXMLFile, "/css:rules");
218 |
219 | //alle native-names sammeln ==> in XML suchen?
220 | var myNativeNames = String(myXMLRoot.xpath("/css:rule/@native-name"));
221 | var myCssRegExpArray = [];
222 |
223 | n = 0;
224 | while (myXMLRoot.xpath("/css:rule/@regex")[n] != null) {
225 | var myCssRegExp = myXMLRoot.xpath("/css:rule/@regex")[n];
226 | myCssString = String(myCssRegExp);
227 | myCssRegExpArray.push(myCssString);
228 | n++
229 | } // while
230 |
231 | //alle Absatzformate sammeln
232 | var myParaStyles = getAllStyles(myDoc, "Paragraph");
233 | var myCharStyles = getAllStyles(myDoc, "Character");
234 | var myTableStyles = getAllStyles(myDoc, "Table");
235 | var myCellStyles = getAllStyles(myDoc, "Cell");
236 | var myObjStyles = getAllStyles(myDoc, "Object");
237 |
238 | var myStyleArray = [];
239 | myStyleArray.push(myParaStyles);
240 | myStyleArray.push(myCharStyles);
241 | myStyleArray.push(myTableStyles);
242 | myStyleArray.push(myCellStyles);
243 | myStyleArray.push(myObjStyles);
244 |
245 | // ==============================================
246 | // NEU
247 | var progressLength = 0;
248 | for (var y = 0; y < myStyleArray.length; y++) {
249 | var progressLength = progressLength + myStyleArray[y].length
250 | } // for
251 |
252 | var w = new Window ('palette');
253 | w.text = "Formatnamen werden geprüft..."
254 | w.pbar = w.add ('progressbar', undefined, 0, progressLength);
255 | w.pbar.preferredSize.width = 300;
256 | w.show();
257 | w.pbar.value = 0;
258 |
259 | //Absatzformte mit NativeNames vergleichen
260 | for (var j = 0; j < myStyleArray.length; j++) {
261 |
262 | var myArray = new Array;
263 | var myArray = myStyleArray[j];
264 | var myIndex = j;
265 |
266 | for (var i = 0; i < myArray.length; i++) {
267 |
268 | var myCurrentStyleTilde = myArray[i];
269 | //Tildenformate
270 |
271 | if (myCurrentStyleTilde.indexOf("~") != -1) {
272 | var myCurrentIndexOf = myCurrentStyleTilde.indexOf("~");
273 | var myCurrentStyle = myCurrentStyleTilde.slice(0, myCurrentIndexOf);
274 | } // if
275 | else {
276 | var myCurrentStyle = myCurrentStyleTilde
277 | } // else
278 |
279 | //wird das Format verwendet?
280 | if (myIndex == 0) {
281 | var type = "Paragraph"
282 | var myStyleList = allMissingParaStyles
283 | } // if
284 | else if (myIndex == 1) {
285 | var type = "Character"
286 | var myStyleList = allMissingCharStyles
287 | } // else if
288 | else if (myIndex == 2) {
289 | var type = "Table"
290 | var myStyleList = allMissingTableStyles
291 | } // else if
292 | else if (myIndex == 3) {
293 | var type = "Cell"
294 | var myStyleList = allMissingCellStyles
295 | } // else if
296 | else if (myIndex == 4) {
297 | var type = "Object"
298 | var myStyleList = allMissingObjStyles
299 | } // else if
300 |
301 | var myMissingStyle = getStyle(myCurrentStyleTilde, myDoc, type);
302 | app.changeTextPreferences = NothingEnum.nothing;
303 | app.findTextPreferences = NothingEnum.nothing;
304 |
305 | if (type == "Paragraph") {
306 | app.findTextPreferences.appliedParagraphStyle = myMissingStyle
307 | myFoundItems = [];
308 | myFoundItems = app.findText(true)
309 | if (myFoundItems.length != 0) {
310 | myMissingStyle = getFullStyleName(myMissingStyle, type);
311 | var found = true;
312 | } // if
313 | else {
314 | found = false;
315 | } // else
316 | } // if
317 |
318 | else if (type == "Character") {
319 | app.findTextPreferences.appliedCharacterStyle = myMissingStyle
320 | myFoundItems = [];
321 | myFoundItems = app.findText(true)
322 | if (myFoundItems.length != 0) {
323 | myMissingStyle = getFullStyleName(myMissingStyle, type);
324 | var found = true;
325 | } // if
326 | else {
327 | found = false;
328 | } // else
329 | } // else if
330 |
331 | else if (type == "Object") {
332 | app.findObjectPreferences.appliedObjectStyles = myMissingStyle;
333 | myFoundItems = [];
334 | myFoundItems = app.findObject(true)
335 | if (myFoundItems.length != 0) {
336 | myMissingStyle = getFullStyleName(myMissingStyle, type);
337 | var found = true;
338 | } // if
339 | else {
340 | found = false;
341 | } // else
342 | } // else if
343 |
344 | else if (type == "Table") {
345 | var result = findTableStyle(myMissingStyle);
346 | if (result == true) {
347 | myMissingStyle = getFullStyleName(myMissingStyle, type);
348 | var found = true;
349 | } // if
350 | else {
351 | found = false;
352 | } // else
353 | } // else if
354 |
355 | else if (type == "Cell") {
356 | var result = findCellStyle(myMissingStyle);
357 | if (result == true) {
358 | myMissingStyle = getFullStyleName(myMissingStyle, type);
359 | myMissingStyle = myMissingStyle.replace(/\s\|\s/g, ":")
360 | var found = true;
361 | } // if
362 | else {
363 | found = false;
364 | } // else
365 | } // else if
366 |
367 |
368 | if (found == true) { // wird im Text verwendet
369 | if (myCurrentStyle.indexOf(":") != -1) {
370 | var myRegExpStyle = myCurrentStyle.replace(/:/g, "_");
371 | }
372 | else {
373 | var myRegExpStyle = myCurrentStyle;
374 | }
375 | var bool = false;
376 | // mit native-names abgleichen
377 | if (myNativeNames.match(myCurrentStyle)) {
378 | bool = true;
379 | }
380 | // mit RegExp abgleichen
381 | if (bool == false) {
382 |
383 | // ACHTUNG: Funktion regex.test() löst Bug in ID aus -> System stürzt ab. Daher der Abgleich der Regexe über Grep-Suche/Ersetzen in ID
384 |
385 | var newFrame = app.activeDocument.pages[0].textFrames.add(); // neune temporären Rahmen anlegen
386 | newFrame.contents = myRegExpStyle; // Namen des AF einfügen
387 |
388 | for (var k = 0; k < myCssRegExpArray.length; k++) { // durch alle cssaRegExp loopen
389 | app.changeGrepPreferences = NothingEnum.nothing;
390 | app.findGrepPreferences = NothingEnum.nothing;
391 | app.findGrepPreferences.findWhat = myCssRegExpArray[k];
392 | myFoundItems = [];
393 | myFoundItems = newFrame.paragraphs[0].findGrep(true); // Abgleich mit dem Text im neuen Textrahmen = Name des verwendeten AF
394 | if (myFoundItems.length != 0) { // wenn myFoundItems.length > 1, matcht aktuelle RegExp auf den Namen des AF
395 | bool = true; // -> Verwendung des Namens erlaubt -> bool = true wird weitergegeben
396 | break;
397 | } // if // auf Anhieb gefunden: weiter
398 | else {}
399 | app.changeGrepPreferences = NothingEnum.nothing;
400 | app.findGrepPreferences = NothingEnum.nothing;
401 | } // for
402 |
403 | newFrame.remove() // temporären Textrahmen wieder löschen
404 | } // if
405 | else {}
406 |
407 | // nirgendwo gefunden
408 | if (bool == false) {
409 | myStyleList.push(myMissingStyle)
410 | } // if
411 | } // if
412 | else {} // else // AF wird nicht verwendet
413 | w.pbar.value = w.pbar.value + 1;
414 | } // for
415 | w.pbar.value = w.pbar.value + 1;
416 | } // for
417 |
418 | myDoc.save();
419 |
420 | if (allMissingParaStyles.length != 0) {
421 | var logText = createLogText(allMissingParaStyles, "Absatzformate:\n");
422 | }
423 | if (allMissingCharStyles.length != 0) {
424 | logText = createLogText(allMissingCharStyles, logText += "\nZeichenformate:\n");
425 | }
426 | if (allMissingTableStyles.length != 0) {
427 | logText = createLogText(allMissingTableStyles, logText += "\nTabellenformate:\n");
428 | }
429 | if (allMissingCellStyles.length != 0) {
430 | logText = createLogText(allMissingCellStyles, logText += "\nZellenformate:\n");
431 | }
432 | if (allMissingObjStyles.length != 0) {
433 | logText = createLogText(allMissingObjStyles, logText += "\nObjektformate:\n");
434 | }
435 | if (allMissingParaStyles.length == 0 && allMissingCharStyles.length == 0 && allMissingTableStyles.length == 0 && allMissingCellStyles.length == 0 && allMissingObjStyles.length == 0) {
436 | w.close();
437 | alert("Prüfung der Formatnamen beendet: \nAlles in Ordnung!")
438 | }
439 | else {
440 | var logName = "/PreExportCeck_falsche-Formatnamen.txt"
441 | saveAs(logText, logName);
442 | w.close();
443 | showList(allMissingParaStyles, allMissingCharStyles, allMissingTableStyles, allMissingCellStyles, allMissingObjStyles)
444 | }
445 | } // if
446 | else {} // else
447 | } // function
448 |
449 |
450 | // --------------------------------------------------------------------------
451 |
452 | function getStyle(_styleName, _doc, _type) {
453 | var _indexOfColon = _styleName.lastIndexOf(":")
454 |
455 | if (_type == "Paragraph") {
456 | var _allStyles = _doc.paragraphStyles
457 | var _allGroups = _doc.paragraphStyleGroups
458 | if (_indexOfColon <= 0) { // keine Gruppe
459 | var _styleName = _allStyles.item(_styleName);
460 | } // if
461 | else { // in Gruppen
462 | var styleNameArray = _styleName.split(":");
463 | var group = _allGroups.item(styleNameArray[0]);
464 | for (var l = 1; l < styleNameArray.length - 1; l++) {
465 | group = group.paragraphStyleGroups.item(styleNameArray[l]);
466 | } // for
467 | var _styleName = group.paragraphStyles.item(styleNameArray[styleNameArray.length - 1]);
468 | } // else
469 | } // if
470 |
471 | else if (_type == "Character") {
472 | var _allStyles = _doc.characterStyles
473 | var _allGroups = _doc.characterStyleGroups
474 | if (_indexOfColon <= 0) { // keine Gruppe
475 | var _styleName = _allStyles.item(_styleName);
476 | } // if
477 | else { // in Gruppen
478 | var styleNameArray = _styleName.split(":");
479 | var group = _allGroups.item(styleNameArray[0]);
480 | for (var l = 1; l < styleNameArray.length - 1; l++) {
481 | group = group.characterStyleGroups.item(styleNameArray[l]);
482 | } // for
483 | var _styleName = group.characterStyles.item(styleNameArray[styleNameArray.length - 1]);
484 | } // else
485 | } // else if
486 | else if (_type == "Table") {
487 | var _allStyles = _doc.tableStyles
488 | var _allGroups = _doc.tableStyleGroups
489 | if (_indexOfColon <= 0) { // keine Gruppe
490 | var _styleName = _allStyles.item(_styleName);
491 | } // if
492 | else { // in Gruppen
493 | var styleNameArray = _styleName.split(":");
494 | var group = _allGroups.item(styleNameArray[0]);
495 | for (var l = 1; l < styleNameArray.length - 1; l++) {
496 | group = group.tableStyleGroups.item(styleNameArray[l]);
497 | } // for
498 | var _styleName = group.tableStyles.item(styleNameArray[styleNameArray.length - 1]);
499 | } // else
500 | } // else if
501 | else if (_type == "Cell") {
502 | var _allStyles = _doc.cellStyles
503 | var _allGroups = _doc.cellStyleGroups
504 | if (_indexOfColon <= 0) { // keine Gruppe
505 | var _styleName = _allStyles.item(_styleName);
506 | } // if
507 | else { // in Gruppen
508 | var styleNameArray = _styleName.split(":");
509 | var group = _allGroups.item(styleNameArray[0]);
510 | for (var l = 1; l < styleNameArray.length - 1; l++) {
511 | group = group.cellStyleGroups.item(styleNameArray[l]);
512 | } // for
513 | var _styleName = group.cellStyles.item(styleNameArray[styleNameArray.length - 1]);
514 | } // else
515 | } // else if
516 | else if (_type == "Object") {
517 | var _allStyles = _doc.objectStyles
518 | var _allGroups = _doc.objectStyleGroups
519 | if (_indexOfColon <= 0) { // keine Gruppe
520 | var _styleName = _allStyles.item(_styleName);
521 | } // if
522 | else { // in Gruppen
523 | var styleNameArray = _styleName.split(":");
524 | var group = _allGroups.item(styleNameArray[0]);
525 | for (var l = 1; l < styleNameArray.length - 1; l++) {
526 | group = group.objectStyleGroups.item(styleNameArray[l]);
527 | } // for
528 | var _styleName = group.objectStyles.item(styleNameArray[styleNameArray.length - 1]);
529 | } // else
530 | } // else if
531 | return _styleName
532 | } // function
533 |
534 | // --------------------------------------------------------------------------
535 |
536 | function getStyleOne(_styleName, _doc, _type) {
537 | var _indexOfColon = _styleName.lastIndexOf(":")
538 |
539 | // old
540 | if (_type == "Paragraph") {
541 | var _allStyles = _doc.paragraphStyles
542 | var _allGroups = _doc.paragraphStyleGroups
543 | if (_indexOfColon <= 0) { // keine Gruppe
544 | var _styleName = _allStyles.item(_styleName);
545 | } // if
546 | else { // in Gruppen
547 | var styleNameArray = _styleName.split(":");
548 | var group = _allGroups.item(styleNameArray[0]);
549 | for (var l = 1; l < styleNameArray.length - 1; l++) {
550 | group = group.paragraphStyleGroups.item(styleNameArray[l]);
551 | } // for
552 | var _styleName = group.paragraphStyles.item(styleNameArray[styleNameArray.length - 1]);
553 | } // else
554 | } // if
555 |
556 | else if (_type == "Character") {
557 | var _allStyles = _doc.characterStyles
558 | var _allGroups = _doc.characterStyleGroups
559 | if (_indexOfColon <= 0) { // keine Gruppe
560 | var _styleName = _allStyles.item(_styleName);
561 | } // if
562 | else { // in Gruppen
563 | var styleNameArray = _styleName.split(":");
564 | var group = _allGroups.item(styleNameArray[0]);
565 | for (var l = 1; l < styleNameArray.length - 1; l++) {
566 | group = group.characterStyleGroups.item(styleNameArray[l]);
567 | } // for
568 | var _styleName = group.characterStyles.item(styleNameArray[styleNameArray.length - 1]);
569 | } // else
570 | } // else if
571 | else if (_type == "Table") {
572 | var _allStyles = _doc.tableStyles
573 | var _allGroups = _doc.tableStyleGroups
574 | if (_indexOfColon <= 0) { // keine Gruppe
575 | var _styleName = _allStyles.item(_styleName);
576 | } // if
577 | else { // in Gruppen
578 | var styleNameArray = _styleName.split(":");
579 | var group = _allGroups.item(styleNameArray[0]);
580 | for (var l = 1; l < styleNameArray.length - 1; l++) {
581 | group = group.tableStyleGroups.item(styleNameArray[l]);
582 | } // for
583 | var _styleName = group.tableStyles.item(styleNameArray[styleNameArray.length - 1]);
584 | } // else
585 | } // else if
586 | else if (_type == "Cell") {
587 | var _allStyles = _doc.cellStyles
588 | var _allGroups = _doc.cellStyleGroups
589 | if (_indexOfColon <= 0) { // keine Gruppe
590 | var _styleName = _allStyles.item(_styleName);
591 | } // if
592 | else { // in Gruppen
593 | var styleNameArray = _styleName.split(":");
594 | var group = _allGroups.item(styleNameArray[0]);
595 | for (var l = 1; l < styleNameArray.length - 1; l++) {
596 | group = group.cellStyleGroups.item(styleNameArray[l]);
597 | } // for
598 | var _styleName = group.cellStyles.item(styleNameArray[styleNameArray.length - 1]);
599 | } // else
600 | } // else if
601 | else if (_type == "Object") {
602 | var _allStyles = _doc.objectStyles
603 | var _allGroups = _doc.objectStyleGroups
604 | if (_indexOfColon <= 0) { // keine Gruppe
605 | var _styleName = _allStyles.item(_styleName);
606 | } // if
607 | else { // in Gruppen
608 | var styleNameArray = _styleName.split(":");
609 | var group = _allGroups.item(styleNameArray[0]);
610 | for (var l = 1; l < styleNameArray.length - 1; l++) {
611 | group = group.objectStyleGroups.item(styleNameArray[l]);
612 | } // for
613 | var _styleName = group.objectStyles.item(styleNameArray[styleNameArray.length - 1]);
614 | } // else
615 | } // else if
616 | return _styleName
617 | } // function
618 |
619 |
620 | // --------------------------------------------------------------------------
621 |
622 | function findMatch(_currentParaStyle, _allNativeNames, _bool) {
623 | var _bool = false;
624 | for (var i = 0; i < _allNativeNames.length; i++) {
625 | var _currentNativeName = _allNativeNames[i];
626 | if (_currentParaStyle.match(_currentNativeName)) {
627 | _bool = true;
628 | break
629 | } // if
630 | else {
631 | _bool = false
632 | } // else
633 | } // for
634 | return _bool
635 | } // function
636 |
637 |
638 | // --------------------------------------------------------------------------
639 |
640 | function getAllStyles(myDoc, type) {
641 | if (type == "Paragraph") {
642 | var all_styles = myDoc.allParagraphStyles
643 | } // if
644 | else if (type == "Character") {
645 | var all_styles = myDoc.allCharacterStyles
646 | } // else if
647 | else if (type == "Table") {
648 | var all_styles = myDoc.allTableStyles
649 | } // else if
650 | else if (type == "Cell") {
651 | var all_styles = myDoc.allCellStyles
652 | } // else if
653 | else if (type == "Object") {
654 | var all_styles = myDoc.allObjectStyles
655 | } // else if
656 |
657 | var all_style_names = new Array;
658 |
659 | for (var i = 0; i < all_styles.length; i++) {
660 | a_name = all_styles[i].name;
661 | var g = all_styles[i];
662 | while (g.parent.constructor !== Document) {
663 | g = g.parent;
664 | a_name = g.name + ':' + a_name
665 | } // while
666 | a_name = a_name;
667 | all_style_names.push(a_name)
668 | } // for
669 | return all_style_names
670 | } // function
671 |
672 |
673 | // --------------------------------------------------------------------------
674 |
675 | function myGetScriptPath() {
676 | try {
677 | myFile = app.activeScript.path
678 | } // try
679 | catch (myError) {
680 | myFile = myError.fileName
681 | } // catch
682 | return myFile
683 | } // function
684 |
685 |
686 | // --------------------------------------------------------------------------
687 |
688 | function loadJS(xmlFile, type) {
689 | xmlFile = new File(xmlFile);
690 | xmlFile.encoding = "UTF-8";
691 | xmlFile.open("r");
692 | var xmlStr = xmlFile.read();
693 | xmlFile.close();
694 | var xml = new XML(xmlStr);
695 | var root = xml.xpath(type);
696 | return root;
697 | } // function
698 |
699 |
700 | // --------------------------------------------------------------------------
701 |
702 | function getFullStyleName(_style, _type) {
703 | var _styleName = _style.name
704 | var _group = _style;
705 | while (_group.parent.constructor !== Document) {
706 | _group = _group.parent;
707 | var _styleName = _group.name + ' | ' + _styleName
708 | } // while
709 | _styleName = _styleName;
710 | return _styleName
711 | } // function
712 |
713 |
714 | // --------------------------------------------------------------------------
715 |
716 | function showList(_allMissingParaStyles, _allMissingCharStyles, _allMissingTableStyles, _allMissingCellStyles, _allMissingObjStyles) {
717 | var myWindow = new Window ("palette", undefined, undefined);
718 | myWindow.text = "Folgende Formate konnten in cssa.xml nicht gefunden werden:";
719 | myWindow.orientation = "row";
720 | myWindow.alignChildren = "fill";
721 | var stylesGroup = myWindow.add ("group {alignChildren: ['left', 'fill']}");
722 | var stylesGroupPanel = stylesGroup.add ("panel", undefined, undefined);
723 | var stylesGroupList = stylesGroupPanel.add ("listbox", undefined, undefined, {multiselect: false});
724 | stylesGroupList.alignment = "fill";
725 | stylesGroupList.preferredSize = [500, 400];
726 |
727 |
728 | if (_allMissingParaStyles.length != 0) {
729 | for (var i = 0; i < _allMissingParaStyles.length; i++) {
730 | var listitem = stylesGroupList.add("item");
731 | listitem.text = "Absatzformat " + _allMissingParaStyles[i];
732 | } // for
733 | } // if
734 | else {
735 | var listitem = stylesGroupList.add ("item");
736 | listitem.enabled = false;
737 | listitem.text = "Absatzformate: Alles in Ordnung!";
738 | }
739 |
740 | var listitem = stylesGroupList.add("item");
741 | listitem.text = "";
742 | listitem.enabled = false;
743 | if (_allMissingCharStyles.length != 0) {
744 | for (var i = 0; i < _allMissingCharStyles.length; i++){
745 | var listitem = stylesGroupList.add ("item");
746 | listitem.text = "Zeichenformat " +_allMissingCharStyles[i]
747 | } // for
748 | } // if
749 | else {
750 | var listitem = stylesGroupList.add ("item");
751 | listitem.enabled = false;
752 | listitem.text = "Zeichenformate: Alles in Ordnung!";
753 | }
754 |
755 |
756 | var listitem = stylesGroupList.add("item");
757 | listitem.text = "";
758 | listitem.enabled = false;
759 | if (_allMissingObjStyles.length != 0) {
760 | for (var i = 0; i < _allMissingObjStyles.length; i++) {
761 | var listitem = stylesGroupList.add ("item");
762 | listitem.text = "Objektformat " + _allMissingObjStyles[i]
763 | } // for
764 | } // if
765 | else {
766 | var listitem = stylesGroupList.add ("item");
767 | listitem.enabled = false;
768 | listitem.text = "Objektformate: Alles in Ordnung!";
769 | }
770 |
771 | var listitem = stylesGroupList.add("item");
772 | listitem.text = "";
773 | listitem.enabled = false;
774 | var listitem = stylesGroupList.add("item");
775 | listitem.text = "----------------------------------------------------------------------------------------";
776 | listitem.enabled = false;
777 | var listitem = stylesGroupList.add ("item");
778 | listitem.text = "Hinweis: Automatische Suche von Tabellen- und Zellenformate nicht per Skript möglich."; // anpassen???
779 | listitem.enabled = false;
780 | var listitem = stylesGroupList.add ("item");
781 | listitem.text = "----------------------------------------------------------------------------------------";
782 | listitem.enabled = false;
783 |
784 |
785 | var listitem = stylesGroupList.add("item");
786 | listitem.text = "";
787 | listitem.enabled = false;
788 | if (_allMissingTableStyles.length != 0) {
789 | for (var i = 0; i < _allMissingTableStyles.length; i++) {
790 | var listitem = stylesGroupList.add ("item");
791 | listitem.enabled = false;
792 | listitem.text = "Tabellenformat " + _allMissingTableStyles[i]
793 | } // for
794 | } // if
795 | else {
796 | var listitem = stylesGroupList.add ("item");
797 | listitem.enabled = false;
798 | listitem.text = "Tabellenformate: Alles in Ordnung!";
799 | }
800 |
801 | var listitem = stylesGroupList.add("item");
802 | listitem.text = "";
803 | listitem.enabled = false;
804 | if (_allMissingCellStyles.length != 0) {
805 | for (var i = 0; i < _allMissingCellStyles.length; i++) {
806 | var listitem = stylesGroupList.add ("item");
807 | listitem.enabled = false;
808 | listitem.text = "Zellenformat " +_allMissingCellStyles[i];
809 | } // for
810 | } // if
811 | else {
812 | var listitem = stylesGroupList.add ("item");
813 | listitem.enabled = false;
814 | listitem.text = "Zellenformate: Alles in Ordnung!";
815 | }
816 |
817 | var group1 = myWindow.add("group", undefined, {name: "group1"});
818 | group1.orientation = "column";
819 | group1.alignChildren = ["left","top"];
820 | group1.spacing = 10;
821 | group1.margins = 0;
822 |
823 | var button1 = group1.add("button", undefined, undefined, {name: "button1"});
824 | button1.text = "Format suchen";
825 | button1.preferredSize.width = 130;
826 | button1.onClick = function() {userSearch(stylesGroupList.selection)} // function
827 |
828 | var button4 = group1.add("button", undefined, undefined, {name: "button4"});
829 | button4.text = "Liste aktualisieren";
830 | button4.preferredSize.width = 130;
831 | button4.onClick = function() {myWindow.close();
832 | $.sleep(400);
833 | checkStyles()
834 | } // function
835 |
836 | var button3 = group1.add("button", undefined, undefined, {name: "button3"});
837 | button3.text = "idml exportieren";
838 | button3.preferredSize.width = 130;
839 | button3.onClick = function() {myWindow.close();
840 | $.sleep(400);
841 | exportIdml()
842 | } // function
843 |
844 | var button2 = group1.add("button", undefined, undefined, {name: "cancel"});
845 | button2.text = "Schließen";
846 | button2.preferredSize.width = 130;
847 | button2.onClick = function() {
848 | myDoc.save();
849 | myWindow.close()
850 | } // function
851 |
852 | myWindow.show();
853 | } // function
854 |
855 |
856 | // --------------------------------------------------------------------------
857 |
858 | function showDialog(_conditionName, _bool) {
859 | var dialog = new Window ("dialog", undefined, undefined);
860 | dialog.text = "Bedingung entfernen";
861 | dialog.orientation = "row";
862 | dialog.alignChildren = ["center","top"];
863 | dialog.spacing = 10;
864 | dialog.margins = 16;
865 |
866 | var group1 = dialog.add("group", undefined, {name: "group1"});
867 | group1.orientation = "column";
868 | group1.alignChildren = ["center","center"];
869 | group1.spacing = 10;
870 | group1.margins = 0;
871 |
872 | var statictext1 = group1.add("statictext", undefined, undefined, {name: "statictext1"});
873 | statictext1.text = "Soll der bedingte Text " + _conditionName + " von markierter Stelle entfernt werden?";
874 | statictext1.justify = "center";
875 |
876 | var group2 = group1.add("group", undefined, {name: "group2"});
877 | group2.orientation = "row";
878 | group2.alignChildren = ["center","center"];
879 | group2.spacing = 10;
880 | group2.margins = 0;
881 |
882 |
883 | var button1 = group2.add("button", undefined, undefined, {name: "button1"});
884 | button1.text = "Ja";
885 | button1.onClick = function() {
886 | dialog.close();
887 | $.sleep (300);
888 | }
889 |
890 | var button2 = group2.add("button", undefined, undefined, {name: "cancel"});
891 | button2.text = "Nein";
892 | button2.onClick = function() {
893 | dialog.close();
894 | $.sleep (300);
895 | } // function
896 |
897 | dialog.show();
898 | } // function
899 |
900 |
901 | // --------------------------------------------------------------------------
902 |
903 | function exportIdml() {
904 |
905 | for (var i = 0; i < myConditions.length; i++) {
906 | for (var j = 0; j < myAllowdConditions.length; j++) {
907 | if (myConditions[i].name.match(myAllowdConditions[j])) {
908 | myConditions[i].visible = true
909 | break
910 | } // if
911 | else {
912 | myConditions[i].visible = false
913 | } // else
914 | } // for
915 | } // for
916 |
917 | // Hier export
918 | var chapters = [];
919 | chapters.push(myDoc);
920 | var p_list = progress_list (create_list (chapters), '*.idml wird exportiert ...');
921 | for (var i = 0; i < chapters.length; i++) {
922 | try {
923 | p_list[i].text = '+';
924 | myFile = new File (myDoc.filePath + "\\" + myDoc.name.replace (/indd$/, 'idml'));
925 | myDoc.exportFile(ExportFormat.INDESIGN_MARKUP, myFile, false);
926 | } // try
927 | catch(e){alert(e);};
928 | } // for
929 | p_list[0].parent.parent.close ();
930 |
931 | // Bedingungen wieder ein- bzw. ausblenden wie vor Export
932 | for (var i = 0; i < myConditions.length; i++) {
933 | var visible = conditionArray[i]
934 | myConditions[i].visible = visible
935 | } // for
936 |
937 | alert("Fertig!")
938 | } // function
939 |
940 |
941 | // --------------------------------------------------------------------------
942 |
943 | function progress_list (array, title)
944 | {
945 | var txt = [];
946 | dlg___ = new Window ('palette', title);
947 | dlg___.orientation = 'row';
948 | var gr1 = dlg___.add ('group');
949 | gr1.orientation = 'column';
950 | gr1.alignChildren = ['left','top'];
951 | for (var i = 0; i < array.length; i++)
952 | {
953 | txt[i] = gr1.add ('statictext', undefined, '');
954 | txt[i].characters = 1
955 | }
956 | var gr2 = dlg___.add ('group');
957 | gr2.minimumSize.width = 200;
958 | gr2.orientation = 'column';
959 | gr2.alignChildren = ['left','top'];
960 | for (var i = 0; i < array.length; i++)
961 | gr2.add ('statictext', undefined, array[i]);
962 | dlg___.show();
963 | return txt;
964 | }
965 |
966 |
967 | // --------------------------------------------------------------------------
968 |
969 | function create_list (f)
970 | {
971 | var array = [];
972 | for (i = 0; i < f.length; i++)
973 | array.push (f[i].name);
974 | return array
975 | }
976 |
977 |
978 | // --------------------------------------------------------------------------
979 |
980 | function userSearch(_selection) {
981 | if (_selection == null || _selection.text.match("\-\-")) {
982 | alert("Bitte wählen Sie ein Format aus.")
983 | } // if
984 | else {
985 | app.changeObjectPreferences = NothingEnum.nothing;
986 | app.findObjectPreferences = NothingEnum.nothing;
987 | app.changeGrepPreferences = NothingEnum.nothing;
988 | app.findGrepPreferences = NothingEnum.nothing;
989 | app.changeTextPreferences = NothingEnum.nothing;
990 | app.findTextPreferences = NothingEnum.nothing;
991 |
992 | app.scriptMenuActions.itemByID(18694).invoke()
993 | if (_selection.text.match("Absatzformat")) {
994 | var type = "Paragraph"
995 | var mySelectedText = _selection.text;
996 | var myNewSelectedText = mySelectedText.slice(19, mySelectedText.length)
997 | myNewReplacedText = myNewSelectedText.replace(/\s/g, ""); // whitespace entfernen
998 | myNewReplacedText = myNewSelectedText.replace(/\s\|\s/g, ":")
999 | var mySelectedStyle = getStyleOne(myNewReplacedText, myDoc, type)
1000 | app.findGrepPreferences.appliedParagraphStyle = mySelectedStyle
1001 | app.findTextPreferences.appliedParagraphStyle = mySelectedStyle
1002 | } // if
1003 |
1004 | else if (_selection.text.match("Zeichenformat")) {
1005 | var type = "Character"
1006 | var mySelectedText = _selection.text;
1007 | var myNewSelectedText = mySelectedText.slice(19, mySelectedText.length)
1008 | myNewReplacedText = myNewSelectedText.replace(/\s\|\s/g, ":")
1009 | var mySelectedStyle = getStyle(myNewReplacedText, myDoc, type)
1010 |
1011 | app.findGrepPreferences.appliedCharacterStyle = mySelectedStyle
1012 | app.findTextPreferences.appliedCharacterStyle = mySelectedStyle
1013 | } // else if
1014 |
1015 | else if (_selection.text.match("Objektformat")) {
1016 | var type = "Object"
1017 | var mySelectedText = _selection.text;
1018 | var myNewSelectedText = mySelectedText.slice(19, mySelectedText.length)
1019 | myNewReplacedText = myNewSelectedText.replace(/\s\|\s/g, ":")
1020 | var mySelectedStyle = getStyle(myNewReplacedText, myDoc, type)
1021 |
1022 | app.findObjectPreferences.appliedObjectStyles = mySelectedStyle
1023 | } // else if
1024 | } // else
1025 | } // function
1026 |
1027 |
1028 | // --------------------------------------------------------------------------
1029 |
1030 | function createLogText(myArray, myText) {
1031 | for (var k = 0; k < myArray.length; k++ ) {
1032 | myText += myArray[k] + "\n";
1033 | } // for
1034 | return myText
1035 | } // function
1036 |
1037 |
1038 | // --------------------------------------------------------------------------
1039 |
1040 | function saveAs(logText, logName) {
1041 | var myTargetFileName = myDoc.filePath;
1042 | var myTargetFile = new File(myTargetFileName + logName);
1043 | myTargetFile.encoding = "UTF-8";
1044 | storeFile(myTargetFile, logText); // ==> Datei mit Text "füllen"
1045 | } // function
1046 |
1047 |
1048 | // --------------------------------------------------------------------------
1049 |
1050 | function storeFile(thisFile, thisText) {
1051 | thisFile.open('w');
1052 | thisFile.write(thisText);
1053 | thisFile.close();
1054 | } // function
1055 |
1056 |
1057 | // --------------------------------------------------------------------------
1058 |
1059 | function findTableStyle(_missingStyle) {
1060 | var _allTables = getTables();
1061 | var _bool = false;
1062 | for (k = 0; k < _allTables.length; k++) {
1063 | if (_allTables[k].appliedTableStyle == _missingStyle) {
1064 | _bool = true;
1065 | return _bool
1066 | break
1067 | } // if
1068 | else {} // else
1069 | } // for
1070 | } // function
1071 |
1072 |
1073 | // --------------------------------------------------------------------------
1074 |
1075 | function findCellStyle (_missingStyle) {
1076 | var _allTables = getTables();
1077 | var _bool = false;
1078 | for (var k = 0; k < _allTables.length; k++) {
1079 | var _allCells = _allTables[k].cells.everyItem().getElements();
1080 | for (var n = 0; n < _allCells.length; n++) {
1081 | var _cell = _allCells[n];
1082 | if (_cell.appliedCellStyle == _missingStyle) {
1083 | _bool = true;
1084 | return _bool
1085 | break
1086 | } // if
1087 | else {} // else
1088 | } // for
1089 | } // for
1090 | } // function
1091 |
1092 |
1093 | // --------------------------------------------------------------------------
1094 |
1095 | function getTables() {
1096 | if (app.selection.length == 0) {
1097 | return app.documents[0].stories.everyItem().tables.everyItem().getElements();
1098 | } // if
1099 | else if (app.selection[0].parent instanceof Cell) {
1100 | return [app.selection[0].parent.parent]
1101 | } // else if
1102 | else if (app.selection[0].hasOwnProperty ('parentStory')) {
1103 | return app.selection[0].parentStory.tables.everyItem().getElements()
1104 | } // else if
1105 | else {
1106 | return app.documents[0].stories.everyItem().tables.everyItem().getElements()
1107 | } // else
1108 | } // function
1109 |
1110 |
1111 | // --------------------------------------------------------------------------
1112 |
1113 | function openDoc() {
1114 | if (app.layoutWindows.length == 0) {
1115 | var file = File.openDialog ("Select a file", "InDesign:*.indd;*.indb;*.idml, InDesign Document:*.indd, InDesign Book:*.indb, InDesign Markup:*.idml", true)
1116 | try {
1117 | app.open(File(file));
1118 | return app.documents[0];
1119 | } catch (e) {
1120 | alert(e);
1121 | return undefined;
1122 | };
1123 | } else {
1124 | return app.documents[0];
1125 | }
1126 | }
1127 |
1128 |
1129 | // --------------------------------------------------------------------------
1130 |
1131 | function saveDoc ( doc ) {
1132 | // check if document is saved
1133 | if ( ( !doc.saved || doc.modified ) ) {
1134 | if ( confirm ("Das Dokument muss gespeichert werden.", undefined)) {
1135 | try {
1136 | doc = doc.save();
1137 | // file successfully saved
1138 | return true;
1139 | } catch ( e ) {
1140 | alert ("The document couldn't be saved.\n" + e);
1141 | // file couldn't be saved
1142 | return false;
1143 | }
1144 | } else {
1145 | // user cancelled the save dialog
1146 | return false;
1147 | }
1148 | } else {
1149 | // file not modified, go on
1150 | return true;
1151 | }
1152 | }
1153 |
1154 |
1155 | // --------------------------------------------------------------------------
1156 |
1157 |
1158 | function writeLog(message, dir, filename){
1159 | var path = dir + '/' + filename;
1160 | createDir(dir);
1161 | var write_file = File(path);
1162 | if (!write_file.exists) {
1163 | write_file = new File(path);
1164 | }
1165 | d = new Date();
1166 | var timestr = "[" + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + "] "
1167 | write_file.open('a', undefined, undefined);
1168 | write_file.encoding = "UTF-8";
1169 | write_file.lineFeed = "Unix";
1170 | write_file.writeln(timestr + message);
1171 | write_file.close();
1172 | }
1173 |
1174 | // --------------------------------------------------------------------------
1175 |
1176 | function createDir (folder) {
1177 | try {
1178 | folder.create();
1179 | return;
1180 | } catch (e) {
1181 | alert (e);
1182 | }
1183 | }
1184 |
--------------------------------------------------------------------------------