Copy link to clipboard
Copied
Is there any way to relink a placed image to a file that does not exist yet? I have an INDD file with a bunch of other INDD files placed as links. I want to replace each of those INDD links with a PDF of the exact same name, but a .pdf extension. This script works when the PDF version of the file already exists:
var links = app.activeDocument.links,
linksLength = links.length;
for (var i = linksLength-1; i >= 0 ; i--) {
var oldLink = links[i];
if(oldLink.linkType == "InDesign Format Name") {
var newLink = new File(oldLink.filePath.replace(".indd",".pdf"));
oldLink.relink(newLink);
}
}
But in my workflow, the PDFs are not yet created so running this script fails because the newLink does not yet exist. I want them to show as missing for now.
Maybe, instead of a "relink", what I need is just some way to change the name of the link that InDesign is looking for without first confirming that it exists.
Any ideas? Thanks!
Actually you can do it, with reinitLink method of Link. See this script I wrote for another answer previously:
/*
Reinit Links
for Adobe Indesign 2022
by m1b
Use this when your file system has changed and current links are broken.
Set `replaceThis` and `withThis` to re-align the file paths.
This is different to Relinker because it doesn't require
modified links to exist.
*/
function main() {
relinker(
// the document to relink
app.activeDocume
...
Copy link to clipboard
Copied
Copy link to clipboard
Copied
That has the same limitation that it first looks to see if the file with the new extension exists. Also, I will need to do this for thousands of links in hundreds of files.
Copy link to clipboard
Copied
Yeah, miss that part. Sorry, but I think you're going to have to actually generate those files first.
Copy link to clipboard
Copied
Hmmm don't think this is possible. I might write a script that removes the old INDD graphic and adds the potential PDF path to the containing frame's label, then a separate script to place file by label.
Copy link to clipboard
Copied
Now you have me thinking and I don't know if this is possible, but what if you exported an IDML file and edited it to change the file extensions of the links?
Copy link to clipboard
Copied
Good idea, Bob!
One could also do a quick test with an IDMS file that is exported from a frame containing an InDesign page.
Hm. Maybe it would make a difference for the experiment if the InDesign document that is placed contains more than one page? ( Just a note to myself … )
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Just did that experiment and it worked.
Replaced .indd with .pdf in the IDMS file with my text editor and removed the whole LinkResourceFormat statement in XML tag <Link. Then I placed the IDMS file and InDesign is showing a missing link to a PDF file instead of an InDesign file.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
I thought of the same thing. Tried it on a file that just contained a link to a single page INDD for which I have a PDF as well. Saved IDML, unzipped, used BBEdit to change the link to the PDF, rezipped, then changed the filename back to IDML. InDesign would not open the file. Perhaps there is a checksum in the file that detects tampering. (In other words, somewhere in the file there is a list of locations and characters. If the character expected at location X does not match what is on the list InDesign will not open the file.)
Either way InDesign will not open the file after converting. It’s not my ZIP utility, because I tested on the original IDML (unzip, recompress, change extension) and it opens file.
Copy link to clipboard
Copied
Hi Scott,
after doing some other tests with that IDMS file ( not with an IDML file ) I realised that other things besides the file extension should be changed as well.
The value for attribute LinkResourceFormat for example. We also need to add a new entry for tag <PDFAttribute with attributes PageNumber, PDFCrop and TransparentBackground and their correct values. Sample:
<PDFAttribute PageNumber="2" PDFCrop="CropMedia" TransparentBackground="true" />
So the script Mark is showing is an excellent way to go.
The correct answer for documents in InDesign CC 2018 and above.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Actually you can do it, with reinitLink method of Link. See this script I wrote for another answer previously:
/*
Reinit Links
for Adobe Indesign 2022
by m1b
Use this when your file system has changed and current links are broken.
Set `replaceThis` and `withThis` to re-align the file paths.
This is different to Relinker because it doesn't require
modified links to exist.
*/
function main() {
relinker(
// the document to relink
app.activeDocument,
// in each link path, replace this string or a regex
/\.indd/,
// with this string
'.pdf'
)
function relinker(doc, replaceThis, withThis) {
var links = doc.links,
counter = 0;
for (var i = 0; i < links.length; i++) {
var linkURI = links[i].linkResourceURI,
newLinkedURI = linkURI.replace(replaceThis, withThis);
links[i].reinitLink(newLinkedURI);
if (linkURI != newLinkedURI)
counter++
}
alert('Reinit ' + counter + ' out of '+links.length + ' links.');
}
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Reinit Links");
All it does is replace .indd with .pdf and "reinit" the links which, unlike "relink", doesn't require a valid file spec.
- Mark
Copy link to clipboard
Copied
TIL about reinitLink
Thanks, Mark!
Copy link to clipboard
Copied
Hi Mark,
great!
FWIW:
Now that I looked it up in DOM documentation, method reinitLink() was introduced with InDesign CC 2018.
Thanks,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Yes! Reinit (and using URI) is exactly what I needed. Thanks!
Copy link to clipboard
Copied
Hi Mark - your input is most appreciated. We are using IDS (CC2022) and what we are trying is to download a layout from a file server and also place all its respecitive links either into the same folder where the IDD documents sites or a subfolder in the INDD folder. We then use IDS to create a PDF, but the links are missing in the layout and thus need to be relinked. We have tried doing this process using ID so we can maually test, and see that there are 2 options in the Links/Panel Menu/Utilities - "Search for missing links" which we run and this does the job and looks for any images in the same folder or subfolder where the layout is stored, but we still need to also run the Links/Panel Menu/ Update All Links for the links to be activated. Is this possible in an IDS script would you know?
Regards
Charles
Copy link to clipboard
Copied
Hi @Charles_Parrington, yes it's possible, if I understand your situation correctly. Feel free to send me a PM if you want to discuss. Or if you have a specific question, please ask it in the forum. If you tag it with "scripting" I will see it.
- Mark
Find more inspiration, events, and resources on the new Adobe Community
Explore Now