Copy link to clipboard
Copied
Hello,
I am trying to use JavaScript to export layers to PNG... I have a working script, that is basically the same as the example in the Adobe Illustrator CS5 JavaScript Reference:
function exportFileToPNG24 (dest) {
if ( app.documents.length > 0 ) {
var exportOptions = new ExportOptionsPNG24();
var type = ExportType.PNG24;
var fileSpec = new File(dest);
exportOptions.antiAliasing = false;
exportOptions.transparency = false;
exportOptions.saveAsHTML = true;
app.activeDocument.exportFile( fileSpec, type, exportOptions );
}
}
However, this will only export the document to 72ppi, and I don't see anywhere in ExportOptionsPNG24 to change this.
If you use Illustrator's UI, instead of scripting, and select File > Export... You get the option to select Screen (72ppi), Medium (150ppi), High (300ppi) or Other.
I found the DocumentRasterResolution constant in the reference, but I can't figure out how to change, or even access the constant?
I assume if I could reset the constant like:
DocumentRasterResolution = 3;
then the above script would export the file to a PNG @ 300 ppi?
No it won't export at the higher resolution. The export of raster images is hardwired to 72 ppi for scripting. Why you can't use the same options available in the Export API is not known but that's the way it is.
edit:
I just made a new New Document Profile called test with a single artboard and a Raster Resolution setting of 72ppi. I then ran this script and it gave me a new document with 2 artboards and a Raster Resolution of 300 ppi.
#target Illustrator
var testPS = new DocumentPreset;
testPS.
Copy link to clipboard
Copied
Unfrotunately it's one of the many things in AI that are doable in the GUI and not from scripting. The best you can do is use the horizontal and vertical scale to make the image larger and then batch resize in Photoshop to get the resolution you want.
Copy link to clipboard
Copied
So, how does the DocumentRasterResolution constant get set in the first place?
Is there an option in the UI, like under File > Document Setup... ?
Copy link to clipboard
Copied
It is a menu item of Effect and refers to the resolution for rasterizing things such as drop shadow effects…
Copy link to clipboard
Copied
I don't think that is correct... otherwise, I should be able to change and save that setting in Effect > Document Raster Effects Settings ..., then my script would export at the higher resolution.
THAT particular raster setting has to do with the Document.rasterEffectSettings property... which is a RasterEffectsOptions object, and like the name implies deals with rasterization of effects... not the doc as a whole.
Copy link to clipboard
Copied
No it won't export at the higher resolution. The export of raster images is hardwired to 72 ppi for scripting. Why you can't use the same options available in the Export API is not known but that's the way it is.
edit:
I just made a new New Document Profile called test with a single artboard and a Raster Resolution setting of 72ppi. I then ran this script and it gave me a new document with 2 artboards and a Raster Resolution of 300 ppi.
#target Illustrator
var testPS = new DocumentPreset;
testPS.numArtboards = 2;
testPS.rasterResolution = DocumentRasterResolution.HighResolution
app.documents.addDocument( "test", testPS);
Copy link to clipboard
Copied
Yeah, I finally stumbled across that too.
I don't really want to mess around with creating and copying documents via JavaScript... seems like a headache.
Guess I'll stick with the initial suggestion of scaling:
exportOptions.horizontalScale = 216;
exportOptions.verticalScale = 216;
Copy link to clipboard
Copied
It appears as though the DocumentRasterResolution constant is only referenced by the DocumentPreset object.
The DocumentPreset object appears to be used when you attempt to create a document with script:
app.documents.addDocument( DocumentPreset );
So, I suppose in theory I could recreate the document entirely with script and then reset the preset raster resolution:
DocumentPreset.rasterResolution = DocumentRasterResolution;
Buuuuuut, screw that.
Scaling it is... apparently.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now