0
Set artboard size not the same as exported size
Explorer
,
/t5/illustrator-discussions/set-artboard-size-not-the-same-as-exported-size/td-p/11272915
Jul 08, 2020
Jul 08, 2020
Copy link to clipboard
Copied
Hi,
I have a script that changes the size of the artboard and the contents on the artboard and then exports it, but I noticed the exported png is off by a few pixel.
var mm = 2.834645;
var px = 1;
var doc = app.activeDocument;
var preffix = "";
var suffix = "";
var foldername = "Icons"
var filepreffix = "Icon"
fullDocName = doc.fullName;
if (app.documents.length > 0) {
// PNG
var optionsPNG24 = new ExportOptionsPNG24();
optionsPNG24.saveAsHTML = true;
optionsPNG24.antiAliasing = true;
optionsPNG24.resolution = 72;
optionsPNG24.transparency = true;
var type = ExportType.PNG24;
app.executeMenuCommand('doc-color-rgb');
doc.artboards[0].artboardRect = [0, 171*px, 307*px, 0];
try {
var norm = doc.layers.getByName("Elemente");
if (norm) {
norm.locked = false;
app.activeDocument.layers["Elemente"].hasSelectedArtwork = true;
app.executeMenuCommand("group");
var normobj = norm.pageItems[0];
var heightTo = 135*px;
var scale = heightTo * 100 / normobj.height;
normobj.resize(scale, scale);
normobj.position = [0*mm, 0*mm];
var ab = doc.artboards[doc.artboards.getActiveArtboardIndex()];
var artboardRight = ab.artboardRect[2];
var artboardBottom = ab.artboardRect[3];
var myPageItem = doc.pageItems[0];
var horziontalCenterPosition = (artboardRight - myPageItem.width)/2;
var verticalCenterPosition = (artboardBottom + myPageItem.height)/.89;
myPageItem.position = [horziontalCenterPosition, verticalCenterPosition];
}
} catch (e) {}
try {
var rect = doc.layers.getByName("Ebene 2");
if (rect) {
rect.locked = false;
rect.pathItems[0].strokeWidth = 4;
rect.locked = false;
var rectobj = rect.pathItems[0];
var widthTo = 307*px;
var scale = widthTo * 100 / rectobj.width;
rectobj.resize(scale, scale);
rectobj.position = [0*mm, 171*px];
}
} catch (e) {}
var param = doc.name.split('.');
realDocName = param[0];
file = preffix+filepreffix+realDocName+'_og'+suffix;
folder = preffix+foldername;
var f = new Folder(doc.path + "/" + folder);
if (!f.exists)
f.create();
var saveName = new File ( f + "/" + file );
doc.exportFile(saveName, type, optionsPNG24);
doc.close(SaveOptions.DONOTSAVECHANGES);
doc = null;
app.open (fullDocName);
doc = app.activeDocument;
}
TOPICS
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Explore related tutorials & articles
Community Expert
,
LATEST
/t5/illustrator-discussions/set-artboard-size-not-the-same-as-exported-size/m-p/11273278#M184854
Jul 08, 2020
Jul 08, 2020
Copy link to clipboard
Copied
by default, your PNG is clipped to the Art bounds. If you want to export the whole artboard, you have to use the below property
optionsPNG24.artBoardClipping = true;
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

