• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
12

How to export only certain files/links from Indesign to png or jpg?

Explorer ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

I've been trying to compile exporting script from various scripts to export only Adobe Illustrator files ignoring jpgs/tiffs from id document to png format. Succeeded to "collect" only ai-files, but saving to png-format won't  happen. What is wrong with it? My script is so far:

//#target "InDesign"

var exportPath = Folder.selectDialog("Choose export location");
if (exportPath != null) {
    var doc = app.activeDocument;
    for (var i = 0; i < doc.links.length; i++) {
        var currentLink = doc.links[i];
        if (currentLink.status == LinkStatus.NORMAL && currentLink.filePath.match(/\.ai$/i)) { //Choose only Illustrator links
            try {
            var myNewFileName = currentLink.name.replace(/\.[a-z]{2,4}$/i, '.png'); //Change extension to png
            var newExportFile = new File(exportPath + "/" + myNewFileName); //New path + new file name
           
            // Set EXPORT presets
app.pngExportPreferences.exportResolution = 300;
app.pngExportPreferences.antiAlias = true;
app.pngExportPreferences.pngQuality = PNGQualityEnum.MAXIMUM;
app.pngExportPreferences.pngColorSpace = PNGColorSpaceEnum.RGB;
app.pngExportPreferences.pngExportRange = PNGExportRangeEnum.EXPORT_RANGE;

//alert("New filename " + newExportFile); //Check to see that proper files been chosen
    myNewFileName.exportFile(ExportFormat.PNG_FORMAT, myNewFileName); //Should export *.ai files to png, but no

    } catch (e) {};
        }
    }
}
alert("Done!");
TOPICS
Import and export , Scripting

Views

169

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 02, 2023 Nov 02, 2023

Hi @peetu , You’ll want to export the link item’s parent frame—the equivalent of choosing Selection in the UI. Try this:

 

var exportPath = Folder.selectDialog("Choose export location");
if (exportPath != null) {
    var doc = app.activeDocument;
    var cl, pi, fn;
    for (var i = 0; i < doc.links.length; i++) {
        cl = doc.links[i];
        if (cl.status == LinkStatus.NORMAL && cl.filePath.match(/\.ai$/i)) {
            pi = cl.parent.parent
            fn = cl.name.replace(/\.[a-z]{2,4}
...

Votes

Translate

Translate
Community Expert ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

Hi @peetu , You’ll want to export the link item’s parent frame—the equivalent of choosing Selection in the UI. Try this:

 

var exportPath = Folder.selectDialog("Choose export location");
if (exportPath != null) {
    var doc = app.activeDocument;
    var cl, pi, fn;
    for (var i = 0; i < doc.links.length; i++) {
        cl = doc.links[i];
        if (cl.status == LinkStatus.NORMAL && cl.filePath.match(/\.ai$/i)) {
            pi = cl.parent.parent
            fn = cl.name.replace(/\.[a-z]{2,4}$/i, '.png')
            app.pngExportPreferences.exportResolution = 300;
            app.pngExportPreferences.antiAlias = true;
            app.pngExportPreferences.pngQuality = PNGQualityEnum.MAXIMUM;
            app.pngExportPreferences.pngColorSpace = PNGColorSpaceEnum.RGB;
            app.pngExportPreferences.pngExportRange = PNGExportRangeEnum.EXPORT_RANGE;
            pi.exportFile(ExportFormat.PNG_FORMAT, File(exportPath + "/" + fn))
        }
    }
}
alert("Done!");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

Thank You @rob day a very very many. That worked like a charm. Now I don't have to export about 200 ai-files by  selection. Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

Do you have access to those linked files? 

 

Because, why would you export "previews" from InDesign - if you have original files? 

 

▒► ID-Tasker / ID-Tasker Server - work smart not hard ◄▒

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 03, 2023 Nov 03, 2023

Copy link to clipboard

Copied

Ah, yes @Robert Tkaczyk  I understand your point. I've done that via Bridge, but it is so time consuming.
At the beginning of project there might be two to three hundreds AI drawings per one press printable ID document , but after two or three draft rounds only about hundred which will be in used as a png format in online publication also. Picking only the chosen ai-files (left in document) of the bunch of files by hand takes time and happens mistakes too. It is frustrating.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 03, 2023 Nov 03, 2023

Copy link to clipboard

Copied

If the size from InDesign is what you are looking for - then OK. 

 

But bulk export from original application can also be scripted - and I'm not talking about preselecting from a folder - info about files to export can be collected from InDesign and then native app - Illustrator or Photoshop - can be used to do finall export.

 

If you work on a PC - my ID-Tasker would do this easily - and much more, as you could automatically sort and / or filter by size, location, page, layer, etc. then export only those results... And then you can save it as a Task and next time - just load the Task and run it - on any file / any number of files - you can even automatically process whole server of files... 

If you are on Mac - you would need dedicated PC and WatchedFolders mode. 

 

▒► ID-Tasker / ID-Tasker Server - work smart not hard ◄▒

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 06, 2023 Nov 06, 2023

Copy link to clipboard

Copied

LATEST

That script sounds workable solution. If I happen to work with Windows someday I will consider that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines