Your prescription for increased productivity and profitability
Your client has just sent you a stack of files written in Word format (.doc or .docx). Upon placing the first of the files in an InDesign document, it becomes evident that there is a fair amount of work to do. Images, of course, are embedded and anchored to text. Captions are all over the place. The first task concerns the images. Were images resampled at 300 dpi before being added to the Word document? A cursory glance into InDesign’s Links panel gives you the answer you anticipated: of course not. And there are lots of them!
Time to think “script.”
Open the Script Editor for AppleScript and paste in the following script:
(*Returns a list of linked image file names, parent page and container, actual resolution (ppi), and current scale factors. *) set thisText to "" tell application "Adobe InDesign CC 2017" set measurement unit of script preferences to points set docRef to document 1 set s to stories of docRef repeat with i from 1 to length of s set rectList to spline items of item i of s if length of rectList > 0 then repeat with thisRect in rectList set thisID to id of thisRect if exists (image 1 of thisRect) then set thisImage to image 1 of thisRect set thisLink to item link of thisImage try set thisName to name of thisLink on error set thisName to "no name" set thisSize to "NA" end try try set aPpi to effective ppi of thisImage set thePpi to "" & item 1 of aPpi & " " & item 2 of aPpi on error set thePpi to "NA" end try set thePage to name of parent page of thisImage try set hScale to (absolute horizontal scale of thisImage) set vScale to (absolute vertical scale of thisImage) set hs to round hScale set vs to round vScale on error set hs to "NA" set vs to "NA" end try set vBounds to geometric bounds of thisRect set wid to round ((item 4 of vBounds) - (item 2 of vBounds)) set hgt to round ((item 3 of vBounds) - (item 1 of vBounds)) set thisEntry to "Image " & thisName & " of rect " & thisID & ¬ " of page " & thePage & " PPI: " & thePpi & " size: " & wid & " x " & hgt ¬ & " pts" & " image scale: " & hs & " x " & vs set thisText to thisText & thisEntry & return end if end repeat end if end repeat end tell thisText
The script is fairly self-explanatory. It simply gets a list of all anchored images in each of the document stories. If anchored images are found, the list is processed and values for the various properties are stored in a string. At the end of the script, the string is placed in the Result window for the editor.
Each entry of the script will read similar to the following.
Image Image501.PNG of rect 500 of page 1 PPI: 508.0 1137.0 size: 362 x 209 pts image scale: 59 x 26
This will work fine for a one time script that you will be executing. But if you need to hand the script off to someone, or you decide to save the script for use in the future, you will need to add some refinements.
Inside the tell statement to InDesign, you will want to test for the existence of a document and, if it exists, place its reference in a variable. Replace the
set docRef to document 1 statement with the following:
try set docRef to my getDocRef() on error errStr activate display alert "Error: " & errStr return end try
Next, place the following before the end tell statement at the end of the script
--get path to folder containing the document set folderPath to (file path of docRef) as string --create a file path for text file generation using name of document and file path set fileName to name of docRef if fileName contains "." then set oset to (offset of "." in fileName) - 1 set fileName to (text 1 thru oset) of fileName end if set filePath to folderPath & fileName & ".txt" --open the file for writing set fileRef to open for access file filePath with write permission --write the string created by the script to the file set eof fileRef to 0 write thisText to fileRef starting at eof close access fileRef
Lastly, add the getDocRef handler to the bottom of the script
on getDocRef() set errStr to "Requires saved active document " & return set errStr to errStr & "Make sure your document is saved and try again" tell application "Adobe InDesign CC 2017" if (not (exists active document)) or (saved of active document is false) then error errStr end if return active document end tell end getDocRef
Test the script with a sample document. Open the file created in a plain text editor (it will be in the same folder as the InDesign document). You may wish to print the file out as a handy reference for the person responsible for resampling and refining the image files.
Now that you have a list of the files embedded in the document, you need to unembed the files. Select the files to unembed in InDesign’s Links panel. Right click (Control click) on the selection and choose Unembed Link from the context menu. You are then presented a dialog to determine if files are to be relinked to original or placed in a chosen folder.
…Click No when presented this dialog
Since you do not have the originals, respond by clicking No. You are then presented a choose folder dialog at which time you can either create a folder or navigate to a folder designated for the images. When you click Open, InDesign will then place the image files in the chosen folder for processing while maintaining the links to the files.
It is heartily suggested that a duplicate folder of these image files be kept in a safe location prior to processing. This is just in case of a later need to have access to an original file.
Once the image files have been processed (resampled, and otherwise fixed), the files will relink when you open the InDesign document.
Should you wish to release the anchored images, a similar script can be written to get a list of all anchored images and release the anchor. As part of that script, however, you will probably want to assign an object style for text wrap and stroke. We will save that script for our next blog, so keep tuned in.
Disclaimer: Code samples are to be used as a guide for users to create their own real world scripts and is provided “AS IS”. No representation is made as to the accuracy or completeness of the code. Use of the code and its operation is at the discretion and responsibility of the user.