Skip to main content
Known Participant
September 27, 2022
Question

anyone have idea about how we can covert .ai image into base64 using extend script?

  • September 27, 2022
  • 3 replies
  • 1291 views

anyone have idea about how we can covert .ai image into base64 using extend script?

This topic has been closed for replies.

3 replies

Mylenium
Brainiac
September 28, 2022

I'm not sure what this has to do with scripting. The file needs to exist in some form already and then you can use whatever is your favorite encoding/ packaging tool like WinZip. Otherwise you can encode individual strings in the file using the normal functions provided by the scripting engine.

 

Mylenium

Known Participant
September 29, 2022

I have extend script for saveasPDF but i need extend script for saveasBase64...

try {
// uncomment to suppress Illustrator warning dialogs
// app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

if (app.documents.length > 0 ) {

// Get the folder to save the files into
var destFolder = null;
destFolder = Folder.selectDialog( 'Select folder for PDF files.', '~' );

if (destFolder != null) {
var options, i, sourceDoc, targetFile;

// Get the PDF options to be used
options = this.getOptions();
// You can tune these by changing the code in the getOptions() function.

for ( i = 0; i < app.documents.length; i++ ) {
sourceDoc = app.documents[i]; // returns the document object

// Get the file to save the document as pdf into
targetFile = this.getTargetFile(sourceDoc.name, '.pdf', destFolder);

// Save as pdf
sourceDoc.saveAs( targetFile, options );
}
alert( 'Documents saved as PDF' );
}
}
else{
throw new Error('There are no document open!');
}
}
catch(e) {
alert( e.message, "Script Alert", true);
}

/** Returns the options to be used for the generated files.
@Return PDFSaveOptions object
*/
function getOptions()
{
// Create the required options object
var options = new PDFSaveOptions();
// See PDFSaveOptions in the JavaScript Reference for available options

// Set the options you want below:

// For example, uncomment to set the compatibility of the generated pdf to Acrobat 7 (PDF 1.6)
// options.compatibility = PDFCompatibility.ACROBAT7;

// For example, uncomment to view the pdfs in Acrobat after conversion
// options.viewAfterSaving = true;

return options;
}

/** Returns the file to save or export the document into.
@9397041 docName the name of the document
@9397041 ext the extension the file extension to be applied
@9397041 destFolder the output folder
@Return File object
*/
function getTargetFile(docName, ext, destFolder) {
var newName = "";

// if name has no dot (and hence no extension),
// just append the extension
if (docName.indexOf('.') < 0) {
newName = docName + ext;
} else {
var dot = docName.lastIndexOf('.');
newName += docName.substring(0, dot);
newName += ext;
}

// Create the file object to save to
var myFile = new File( destFolder + '/' + newName );

// Preflight access rights
if (myFile.open("w")) {
myFile.close();
}
else {
throw new Error('Access is denied');
}
return myFile;
}

Known Participant
September 27, 2022

I want to save any .ai image into jepg/base64 format after opening it  in illustrator's extension so please guide me on this?

e.g.

step1: open adobe illustrator

step2: then open any already saved image from local folder into illustrator

step3: add new layer and also add some comments on the image via text tool bar

step4: "MY QUESTION" how i can save this .ai image into jpeg and base64? 

please guide me on this. 

Community Manager
September 27, 2022

Hello @Rishabh22425292b5db,

 

Thanks for reaching out. Kindly try the suggestions shared in this community post (https://community.adobe.com/t5/illustrator-discussions/how-can-i-encode-a-file-into-a-base-64/td-p/10677320) and check if it helps.

 

Looking forward to your response.

 

Thanks,

Anubhav

Known Participant
September 28, 2022

No its not helped.

I want to add a script to save .ai image to base64(which should contain layer automatically).

file->script->saveasBase64  <= need to implement this