Using JavaScript, cannot export png24 with 300 ppi

Community Beginner ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

I have a document that I can export manually with 300ppi resolution, just like it's set in Effect -> Document Raster Effects Settings...

But when I use script, it always seems to default to 72ppi. I tried every other file format and it always sets to 72. Tried using JPEG quality parameter = 100, still resolves to 72ppi.

my document size is 600x600 pt, one artboard, the artboard corners are set at integer values, either at 0 pt or 600 pt. 

Any help would be appreciated!
Here's my code snippet below:

function exportFileToPNG(){

    if (app. documents. length > 0) {

    var exportOptions = new ExportOptionsPNG24() ;

    exportOptions.artBoardClipping = true;

    var type = ExportType. PNG24;

    var file = new File(filePath);

    app.activeDocument.exportFile(file, type, exportOptions);

}
}

TOPICS
Feature request , Import and export , Scripting , SDK

Views

178

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Dec 14, 2021 Dec 14, 2021
There is no function to set PPI in the scripting reference for either JPEG or PNG exports. See here for a possible workaround: https://community.adobe.com/t5/illustrator-discussions/setting-the-resolution-output-in-an-export-png-script/td-p/10568663 Incidentally, Effect > Document Raster Effect Settings doesn't set PPI for export either, it only sets it for raster effects such as drop shadow within Illustrator.

Likes

Translate

Translate
Adobe Community Professional ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

There is no function to set PPI in the scripting reference for either JPEG or PNG exports. See here for a possible workaround:

https://community.adobe.com/t5/illustrator-discussions/setting-the-resolution-output-in-an-export-pn...

 

Incidentally, Effect > Document Raster Effect Settings doesn't set PPI for export either, it only sets it for raster effects such as drop shadow within Illustrator.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

Thanks, Doug! I'll try it later today. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

That worked like a charm! Thanks for pointing to the right answer, Doug!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

i was wondering why to use script to export 1 artboard in a file!

 

easy to do

 

file> export to

Screen Shot 2021-12-14 at 7.16.52 PM.pngScreen Shot 2021-12-14 at 7.17.06 PM.png

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

I wouldn't make any assumptions about why a user would want to use a script to export. It might be a snippet of a larger workflow.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

Manal, just like Doug pointed out, it's a snippet of a workflow that generates thousands of images

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

You can have your script create, load, execute then unload an Action that exports beyond 72:

 

/**
 * Thanks Ten-A! 
 * https://community.adobe.com/t5/illustrator/illustrator-jpegexportoptions-object-properties-are-missing-in-object-model/td-p/8699364?page=1
 *
 *  {String} pth - Filepath for document destination
 */
function exportJPG(pth) {
  //Exports 300ppi CMYK jpg
  var str = "";
  for (var i = 0; i < pth.length; i++) str += u16to8(pth.charCodeAt(i));
  var act =
    "/version 3" +
    "/name [ 4" +
    "	73657431" +
    "]" +
    "/isOpen 1" +
    "/actionCount 1" +
    "/action-1 {" +
    "	/name [ 4" +
    "		61637432" +
    "	]" +
    "	/keyIndex 0" +
    "	/colorIndex 0" +
    "	/isOpen 1" +
    "	/eventCount 1" +
    "	/event-1 {" +
    "		/useRulersIn1stQuadrant 0" +
    "		/internalName (adobe_exportDocument)" +
    "		/localizedName [ 9" +
    "			4578706f7274204173" +
    "		]" +
    "		/isOpen 1" +
    "		/isOn 1" +
    "		/hasDialog 1" +
    "		/showDialog 0" +
    "		/parameterCount 7" +
    "		/parameter-1 {" +
    "			/key 1885434477" +
    "			/showInPalette 0" +
    "			/type (raw)" +
    "			/value < 104" +
    "				0a00000001000000030000000100000000002c01020000000000000001000000" +
    "				69006d006100670065006d006100700000006800720069007300200054007500" +
    "				73006b006f00770073006b00690020002d00200041006e006e00610020004300" +
    "				0000000001000000" +
    "			>" +
    "			/size 104" +
    "		}" +
    "/parameter-2 {/key 1851878757/showInPalette 4294967295" +
    "/type (ustring)/value [ " +
    str.length / 2 +
    " " +
    str +
    "]}" +
    "		/parameter-3 {" +
    "			/key 1718775156" +
    "			/showInPalette -1" +
    "			/type (ustring)" +
    "			/value [ 16" +
    "				4a5045472066696c6520666f726d6174" +
    "			]" +
    "		}" +
    "		/parameter-4 {" +
    "			/key 1702392942" +
    "			/showInPalette -1" +
    "			/type (ustring)" +
    "			/value [ 12" +
    "				6a70672c6a70652c6a706567" +
    "			]" +
    "		}" +
    "		/parameter-5 {" +
    "			/key 1936548194" +
    "			/showInPalette -1" +
    "			/type (boolean)" +
    "			/value 1" +
    "		}" +
    "		/parameter-6 {" +
    "			/key 1935764588" +
    "			/showInPalette -1" +
    "			/type (boolean)" +
    "			/value 1" +
    "		}" +
    "		/parameter-7 {" +
    "			/key 1936875886" +
    "			/showInPalette -1" +
    "			/type (ustring)" +
    "			/value [ 3" +
    "				312d36" +
    "			]" +
    "		}" +
    "	}" +
    "}" +
    "";
  var tmp = File(Folder.desktop + "/set10.aia");
  tmp.open("w");
  tmp.write(act);
  tmp.close();
  app.loadAction(tmp);
  app.doScript("act2", "set1", false);
  app.unloadAction("set1", "");
  tmp.remove();
}
function u16to8(cd) {
  var out =
    cd < 0x80
      ? toHex2(cd)
      : (cd < 0x800
          ? toHex2(((cd >> 6) & 0x1f) | 0xc0)
          : toHex2((cd >> 12) | 0xe0) + toHex2(((cd >> 6) & 0x3f) | 0x80)) +
        toHex2((cd & 0x3f) | 0x80);
  return out;
}
function toHex2(num) {
  var out = "0" + num.toString(16);
  return out.slice(-2);
}

 

ImageCapture is easier but this is another alternative, I've had clients who specifically use Actions to export and using the same Actions as they do ensures the results are identical especially with CMYK or particular settings.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

For PNG24, if you record an Action (destination path doesn't matter) to export to your specs, then export this .aia Action file you can retrofit it into the code above. The concatenation is a bit obnoxious above ha, but essentially you'd swap the above Action text with your own. You'd still need to include the manual section that designates the filepath, which in the above Action is this section:

 

    "/parameter-2 {/key 1851878757/showInPalette 4294967295" +
    "/type (ustring)/value [ " +
    str.length / 2 +
    " " +
    str +
    "]}" +

 

There should be a corresponding parameter-2 looking very similar in yours, you'd have to copy/paste the sections following "/type" and below to replace it.

 

Also! You'd need to accurately have your Action Name and Action Set parameters set in the above snippet within the app.doScript and app.unloadAction methods.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

another alternative for future reference, Export for Screens supports custom Resolution exports and it's available in the Scripting API

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

Oh thanks Carlos! I didn't know that we had access to Export for Screens. That'll be useful. 🙂

 

I found your helpful post that shows the Export For Screens info, but do you know of any updated online docs for scripting Illustrator? I use https://ai-scripting.docsforadobe.dev but it doesn't include the latest additions to the API.

- Mark

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

LATEST

Awesome 8) 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines