In the Illustrator object model, the exportFile()
method exports a file in a specified format with options. The three arguments are specified inside the parentheses of the method. For example, let’s export the active artboard of a document to PNG.
var doc = app.activeDocument;
var opts = new ExportOptionsPNG24();
opts.artBoardClipping = true;
var png = new File(doc.path + "/" + doc.name.split(".")[0] + ".png");
doc.exportFile(png, ExportType.PNG24, opts);
If the document is created in large canvas mode in Adobe Illustrator versions 24.2 and later, exporting to PNG doesn’t work. In this case, Illustrator won’t throw an error, and the try-catch construct won’t catch it either. To warn the user, you’ll need to add a canvas size check to the script.
var doc = app.activeDocument;
var sf = doc.scaleFactor ? doc.scaleFactor : 1;
var opts = new ExportOptionsPNG24();
opts.artBoardClipping = true;
var png = new File(doc.path + "/" + doc.name.split(".")[0] + ".png");
if (sf == 1) {
doc.exportFile(png, ExportType.PNG24, opts);
} else {
alert("Document is in Large Canvas mode.\nExport to PNG is not supported.");
}