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

how to save selected image in inDesign using uxp code

Community Beginner ,
Dec 13, 2023 Dec 13, 2023

Copy link to clipboard

Copied

Can anyone help how to save selected image save in local drive in inDesign uxp code structure. below given code is not working for me.

const app = global.app ?? require("indesign").app;
async function saveImage() {
const selection = app.activeDocument.selection;
if (selection) {
const selectedImage = selection[0];
if (selectedImage) {
try {
const imageCopy = selectedImage.duplicate();
imageCopy.exportFile("JPG", "");
console.log("Image saved successfully!");
imageCopy.remove();
} catch (error) {
console.log("Error saving image: " + error);
}
} else {
console.log("The selected item is not an image.");
}
} else {
console.log("No item selected. Please select an image to save.");
}
}
TOPICS
Activation billing and install , Bug , EPUB , Experiment , Feature request , How to , Import and export , InCopy workflow , Performance , Print , Publish online , Scripting , SDK , Sync and storage , Type , UXP Scripting

Views

332

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 ,
Dec 13, 2023 Dec 13, 2023

Copy link to clipboard

Copied

I don't think your exportFile arguments are correct. I don't think they have changed from JSX to UXP. Think you need to pass a valid File object, but I don't have the API in front of me. 

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 ,
Dec 13, 2023 Dec 13, 2023

Copy link to clipboard

Copied

LATEST

• Function saveImage is defined but not executed. Use `await saveImage()` to execute it

 

• Change the export image type 'JPG' passed to exportFile to ExportFormat.JPG or 1246775072. ExportFormat must be required by yourself

const { app, ExportFormat } = require('indesign') ;

 

• You have to specify a destination path for exportFile

const os = require('os') ;
const dstFolder = path.join(os.homedir(), 'Desktop') ;
imageCopy.exportFile(ExportFormat.JPG, path.join(dstFolder, 'sample.jpg')) ;

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