Javascript Export Options not Applied
I have an issue that caused me hours of troubleshooting, but I still cannot figure out why export options are not being applied to SVG files. Here is my code—if anyone has a slight clue as to what the problem is, I would greatly appreciate feedback. (In this code i even apply the options right before export but it still does not work. I also tried things like exportForScreens or saveAs and all is to no avail)
It is important to at least have 7 decimals places beeing applied.
// Function to export SVG using Adobe's SVG options
function getSVGOptions() {
var options = new ExportOptionsSVG();
options.embedRasterImages = true;
options.fontSubsetting = SVGFontSubsetting.None;
options.cssProperties = SVGCSSPropertyLocation.STYLEATTRIBUTES;
options.documentEncoding = SVGDocumentEncoding.UTF8;
options.DecimalPlaces = 7;
options.Minify = true;
options.Responsive = false;
return options;
}
// Function to export a single artboard as SVG, PNG, and JPG (if applicable)
function exportArtboardAsSeparateFile(doc, artboardIndex, exportFolder, baseName) {
try {
doc.artboards.setActiveArtboardIndex(artboardIndex);
var artboard = doc.artboards[artboardIndex];
var artboardName = artboard.name.replace(/_/g, "-");
var exportBaseName = baseName.replace(/_/g, "-") + "-" + artboardName;
var artboardRect = artboard.artboardRect;
// Collect items to delete outside the active artboard
var itemsToDelete = [];
for (var k = 0; k < doc.pageItems.length; k++) {
var item = doc.pageItems[k];
var itemBounds = item.visibleBounds;
if (itemBounds[0] > artboardRect[2] || itemBounds[2] < artboardRect[0] ||
itemBounds[1] < artboardRect[3] || itemBounds[3] > artboardRect[1]) {
itemsToDelete.push(item);
}
}
// Delete all items outside the artboard
for (var i = 0; i < itemsToDelete.length; i++) {
itemsToDelete[i].remove();
}
// Export SVG using Adobe's options
try {
var svgFile = new File(exportFolder + "/" + exportBaseName + ".svg");
doc.exportFile(svgFile, ExportType.SVG, getSVGOptions());
} catch (e) {
$.writeln("Error exporting SVG for artboard " + artboardIndex + ": " + e.message);
pauseForMemoryRecovery();
}
