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

illustrator javascript export jpg spaces replaced by a dash

Explorer ,
Sep 21, 2023 Sep 21, 2023

The code works very well. The only problem is that there is a hyphen instead of a space. For example,

my-picture-test.jpg.
Is there any way to solve this?

 

 

var doc = app.activeDocument;
exportFileToJPEG();
function exportFileToJPEG() {
    var newpath = doc.path + "/" + doc.name.substring(0, doc.name.length - 2 + "jpg");
    var resolution = 300;
    var exportOptions = new ExportOptionsJPEG();
    var type = ExportType.JPEG;
    var fileSpec = new File(newpath);/// + "jpg");
    exportOptions.antiAliasing = true;
    exportOptions.artBoardClipping = true;
    exportOptions.horizontalScale = resolution * 100 / 72;
    exportOptions.verticalScale = resolution * 100 / 72;
    exportOptions.qualitySetting = 90;
    app.activeDocument.exportFile(fileSpec, type, exportOptions);
}

 

 

TOPICS
Scripting
308
Translate
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
Adobe
Community Expert ,
Sep 21, 2023 Sep 21, 2023

Just go ahead and add in the hypens before saving, then rename the saved JPG back to the original name without spaces.

var doc = app.activeDocument;
exportFileToJPEG();
function exportFileToJPEG() {
  var newName = doc.name.replace(/\.[a-zA-Z]{2,3}$/, ".jpg");
  var newNameWithHyphens = newName.replace(/\s/g, "-");
  var fileSpec = new File(doc.path + "/" + newNameWithHyphens);
  var resolution = 300;
  var exportOptions = new ExportOptionsJPEG();
  var type = ExportType.JPEG;
  exportOptions.antiAliasing = true;
  exportOptions.artBoardClipping = true;
  exportOptions.horizontalScale = (resolution * 100) / 72;
  exportOptions.verticalScale = (resolution * 100) / 72;
  exportOptions.qualitySetting = 90;
  app.activeDocument.exportFile(fileSpec, type, exportOptions);
  fileSpec.rename(newName);
}

 

Translate
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 ,
Sep 21, 2023 Sep 21, 2023
LATEST

Exactly what I was looking for, thank you

Translate
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