Copy link to clipboard
Copied
Hello,
Chapter 12 of the Javascript Scripting Guide talks about loading XML files into elements of an InDesign document, and about styling them using tags-to-style mappings. Given an InCopy ICML file, however, how do I place its content in a document? Using that same XML facility, or is there another and better way of loading and placing ICML files into InDesign documents?
Thank you,
Jens
Copy link to clipboard
Copied
You simply place the ICML-File into a Textframe:
app.activeDocument.textFrames[0].place(icmlFile);
// optional unlink
dok.links.itemByName(icmlFile.name).unlink();
Copy link to clipboard
Copied
grefel​ Thank you for mentioning the TextFrame.place() method, that’s what I was looking for. It takes a File argument though, and Javascript’s File class doesn’t seem to implement a wrapper for a string or stream (which is how the ICML arrives in my case). I might be able to use a temporary file in local storage though, I shall poke around...
I also noticed that line breaks and spaces in the ICML file are replicated exactly, including page breaks that I haven’t quite figured out where they come from.
Thank you!
Copy link to clipboard
Copied
There is no wrapper for String or Stream. I would write a temporary file to disk.
Copy link to clipboard
Copied
grefel​, is it possible that the place() function works differently on 2015.4 (11.4.0.90) than it does on my 12.0.0.81? I ask because a customer does not see any content of the placed ICML file, and since I don’t have that version of InDesign I can’t really test...
Copy link to clipboard
Copied
I'm quite sure that place() works the same way in 2015.4 (11.4.0.90) and 2017 and all the other version since I started scripting with CS3.
To check: Do you use the mentioned code block with unlink:
app.activeDocument.textFrames[0].place(icmlFile);
dok.links.itemByName(icmlFile.name).unlink();
Copy link to clipboard
Copied
Hi Jens,
you could check what placeable file extensions can be used:
// Writes the result to the JavaScript Console of the ExtendScript Toolkit (ESTK)
app.placeableFileExtensions.sort().join("\r");
// Result for e.g. InDesign CS6 v8.1.0 on Mac OSX:
AI
AIF
AIFF
AU
AVI
BMP
CT
DCS
EMF
EPS
F4V
FLV
GIF
JPE
JPEG
JPG
M15
M1A
M1S
M1V
M64
M75
MOV
MP2
MP4
MPA
MPEG
MPG
MPM
MPV
PCC
PCT
PCX
PDD
PIC
PMG
PNG
PSD
RLE
SCT
SWF
TIF
TIFF
TP1
TRP
TXT
WAV
WAVE
WMF
doc
doc
docx
icml
idms
incd
incx
indd
inds
indt
joboptions
mp3
oam
pdp
rtf
txt
utxt
xls
xlsx
However, I did not test, if all of these will work for the Mac version.
And InDesign will be agnostic on cases:
E.g. myDocument.jpg and myDocument.JPG will work alike.
Regards,
Uwe