Skip to main content
Participating Frequently
January 5, 2024
Question

What script can use to convert batch of WMF file to ai file?

  • January 5, 2024
  • 2 replies
  • 557 views

I got hundred of wmf file needed to convert to adobe Illustrator format/ai (with pdf compatible), found some script on the forum , but seem like dated, no longer work on CC2024, can anyone advise the updated script? many thanks

2 replies

Participant
January 8, 2025

This worked for me.

# Save the updated script with summary reporting as a .jsx file for download
script_with_summary_path = "/mnt/data/BatchConvertWMFtoAI_Summary.jsx"

script_content_with_summary = """\
// Adobe Illustrator Script to Batch Convert WMF to AI
// This script opens .wmf files in a folder, crops them to the artwork bounds, and saves them as .ai files.

// Get folder containing the WMF files
var inputFolder = Folder.selectDialog("Select the folder with WMF files");
if (!inputFolder) {
    alert("No folder selected. Script cancelled.");
    exit();
}

// Get list of .wmf files in the folder
var files = inputFolder.getFiles("*.wmf");
if (files.length === 0) {
    alert("No WMF files found in the selected folder.");
    exit();
}

// Initialize counters for summary
var successfulConversions = 0;
var failedConversions = [];

// Loop through all WMF files
for (var i = 0; i < files.length; i++) {
    var file = files[i];
    var doc;

    try {
        doc = app.open(file); // Open WMF file

        // Crop to artwork bounds
        doc.artboards[0].artboardRect = doc.visibleBounds;

        // Save as AI file
        var saveOptions = new IllustratorSaveOptions();
        saveOptions.compatibility = Compatibility.ILLUSTRATOR17; // Broad compatibility
        saveOptions.compressed = true;
        var outputFile = new File(file.path + "/" + file.name.replace(/\\.wmf$/i, ".ai"));
        doc.saveAs(outputFile, saveOptions);

        successfulConversions++;
    } catch (e) {
        failedConversions.push(file.name + " - " + e.message);
    } finally {
        if (doc) doc.close(SaveOptions.DONOTSAVECHANGES);
    }
}

// Create summary message
var summaryMessage = "Batch conversion complete.\\n\\n" +
                     "Successfully converted: " + successfulConversions + " file(s).\\n";
if (failedConversions.length > 0) {
    summaryMessage += "Failed to convert: " + failedConversions.length + " file(s).\\n\\n";
    summaryMessage += "Errors:\\n" + failedConversions.join("\\n");
}

alert(summaryMessage);
"""

with open(script_with_summary_path, "w") as file:
    file.write(script_content_with_summary)

script_with_summary_path
Participating Frequently
January 9, 2025

not work, error

CarlosCanto
Community Expert
Community Expert
January 5, 2024

you should be able to record and action to export to WMF then use Batch to apply such action to a whole folder

 

but post the script you found to see if we can make it work with the latest ai version

Participating Frequently
January 5, 2024

Hi Carlos, thanks, it does work, but the ai format wan't edn up pdf compatible (which is icon not able to preview), any suggestion to encouter this issue?

CarlosCanto
Community Expert
Community Expert
January 5, 2024

does it work if you save manually? then when you save using the Action it doesn't work?