Skip to main content
Inventsable
Legend
June 27, 2020
Answered

Export JPG as 300 ppi?

  • June 27, 2020
  • 3 replies
  • 4866 views

Hi guys, I have an issue where I need to batch export JPGs from files saved as 72 ppi, but the result needs to be 300 ppi. I don't see a way to set this via ExportType.JPEG and ExportOptionsJPEG, and I don't see a way to get the current PPI of Illustrator in order to know how much to scale the image to match.

 

My issues are:

  1. When I use app.activeDocument.exportFile, it produces a smaller image or blurry output compared to what the client wants. I need it to result in 300 ppi but it only produces 72 ppi.
  2. When I use app.activeDocument.imageCapture instead, it appears to be perfect and it doesn't say anywhere that it only supports PNG, but when I export JPG from this and try to place the results in Illustrator, it claims that they're unsupported files and Illustrator doesn't know how to open them. So it appears I'm creating corrupted PNGs which have been renamed as ".jpg" instead of actual JPG images.
This topic has been closed for replies.
Correct answer Charu Rajput

Hi,

Could you please try using actions

 

var dest = Folder(Folder.desktop);

function main() {

    String.prototype.hexEncode = function () {
        var hex = '';
        for (var i = 0; i < this.length; i++) {
            hex += '' + this.charCodeAt(i).toString(16);
        }
        return hex;
    };


    function writeFile(fileDestStr, contents) {
        var newFile = File(fileDestStr);
        newFile.open('w');
        newFile.write(contents);
        newFile.close();
    };


    var actionStr = [
        "/version 3",
        "/name [ 4",
        "54657374",
        "]",
        "/isOpen 1",
        "/actionCount 1",
        "/action-1 {",
        "/name [ 12",
        "53617665204d79204a504547",
        "]",
        "/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",
        "0a00000001000000030000000200000000002c0101000000000000000100000069006d006100670065006d00610070000000310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        ">",
        "/size 104",
        "}",
        "/parameter-2 {",
        "/key 1851878757",
        "/showInPalette -1",
        "/type (ustring)",
        "/value [ PUT_FOLDERPATH_CHAR_LENGTH_HERE",
        "PUT_HEX_FOLDERPATH_HERE",
        "]",
        "}",
        "/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 0",
        "}",
        "/parameter-6 {",
        "/key 1935764588",
        "/showInPalette -1",
        "/type (boolean)",
        "/value 1",
        "}",
        "/parameter-7 {",
        "/key 1936875886",
        "/showInPalette -1",
        "/type (ustring)",
        "/value [ 1",
        "31",
        "]",
        "}",
        "}",
        "}"
    ].join("\n");

    if (app.documents.length == 0) {
        return;
    }


    var destStr = decodeURI(dest.fsName);
    var actionFileDestStr = Folder.desktop + "/MyAction.aia";
    writeFile(actionFileDestStr, actionStr.replace("PUT_FOLDERPATH_CHAR_LENGTH_HERE", destStr.length).replace("PUT_HEX_FOLDERPATH_HERE", destStr.hexEncode()));
    var actionFile = File(actionFileDestStr);
    app.loadAction(actionFile);
    app.doScript("Save My JPEG", "Test");


    //clean up 
    actionFile.remove();
    app.unloadAction("Test", '');
};

main();

 

I have got this a long ago from old thread only. May be it works for you too.

 

3 replies

CarlosCanto
Community Expert
Community Expert
June 27, 2020

besides using actions, the only way to export to 300 was to scale the artwork. Bigger artwork gave us more pixels. The file was still 72 ppi but it gave us decent results mimicking higher resolution.

 

that was until Export For Screens was introduced a couple of versions ago.

 

here is a sample showing both options. Select something before running the script

 

 

// export selection by Resolution
// carlos canto - 06/27/2020
// https://community.adobe.com/t5/illustrator/export-jpg-as-300-ppi/td-p/11244200?cid=101&cgid=18269&page=1

function main() {
    var idoc = app.activeDocument;
    var asset = idoc.assets.addFromSelection();
    asset.assetName = 'myExportedAsset';
    
    var destFolder = Folder('~/desktop');
    var resolution = 300;
    exportItem (asset, destFolder, resolution);
    
    var destPath = destFolder + '/mySaveAsFile.jpg';
    exportFileToJPEG (destPath, resolution);
}

function exportItem(item, destFolder, resolution) {
    // turn create folders off, same as unchecking the setting on the UI Export Assets window
    app.preferences.setIntegerPreference ('plugin/SmartExportUI/CreateFoldersPreference', 0); // don't create subfolders
    
    var whatToExport = new ExportForScreensItemToExport();
    whatToExport.assets = [item.assetID];
    whatToExport.artboards = ''; // don't export artboard
    whatToExport.document = false; // don't export document

    var jpgOptions = new ExportForScreensOptionsJPEG;
    jpgOptions.antiAliasing = AntiAliasingMethod.TYPEOPTIMIZED; // art optimized results in jagged edges, is it a bug?
    jpgOptions.compressionMethod = JPEGCompressionMethodType.BASELINEOPTIMIZED; // BASELINESTANDARD
    jpgOptions.scaleType = ExportForScreensScaleType.SCALEBYRESOLUTION;
    jpgOptions.scaleTypeValue = resolution;
    
    activeDocument.exportForScreens (destFolder, ExportForScreensType.SE_JPEG100, jpgOptions, whatToExport);
}

main();

function exportFileToJPEG (dest, resolution) {
    
    var exportOptions = new ExportOptionsJPEG();
    var type = ExportType.JPEG;
    var fileSpec = new File(dest);
    exportOptions.antiAliasing = true;
    exportOptions.artBoardClipping = false;
    exportOptions.horizontalScale = resolution*100/72; // scaling increases image physical size, 
    exportOptions.verticalScale = resolution*100/72;
    exportOptions.qualitySetting = 100;
    app.activeDocument.exportFile( fileSpec, type, exportOptions );
}

 

 

Carlos 

Inventsable
Legend
June 28, 2020

Looks really promising! Thanks as always Carlos.

CarlosCanto
Community Expert
Community Expert
June 28, 2020

my pleasure Tom.

Legend
June 27, 2020

There is no "current ppi" in Illustrator because it is a vector app. There is no ppi at all (except an unrelated value for raster effects).

Inventsable
Legend
June 27, 2020

That might be technically true but the issue still stands that you export JPG via scripting by default in 72 ppi but I need to export in 300, and this is an available setting within File > Export As that I can't find a scripting solution for other than what Charu shows for loading an action:

femkeblanco
Legend
June 27, 2020

Please excuse the obvious question, but why not export as TIF?  ExportOptionsTIFF has a "resolution" property. 

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
June 27, 2020

Hi,

Could you please try using actions

 

var dest = Folder(Folder.desktop);

function main() {

    String.prototype.hexEncode = function () {
        var hex = '';
        for (var i = 0; i < this.length; i++) {
            hex += '' + this.charCodeAt(i).toString(16);
        }
        return hex;
    };


    function writeFile(fileDestStr, contents) {
        var newFile = File(fileDestStr);
        newFile.open('w');
        newFile.write(contents);
        newFile.close();
    };


    var actionStr = [
        "/version 3",
        "/name [ 4",
        "54657374",
        "]",
        "/isOpen 1",
        "/actionCount 1",
        "/action-1 {",
        "/name [ 12",
        "53617665204d79204a504547",
        "]",
        "/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",
        "0a00000001000000030000000200000000002c0101000000000000000100000069006d006100670065006d00610070000000310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        ">",
        "/size 104",
        "}",
        "/parameter-2 {",
        "/key 1851878757",
        "/showInPalette -1",
        "/type (ustring)",
        "/value [ PUT_FOLDERPATH_CHAR_LENGTH_HERE",
        "PUT_HEX_FOLDERPATH_HERE",
        "]",
        "}",
        "/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 0",
        "}",
        "/parameter-6 {",
        "/key 1935764588",
        "/showInPalette -1",
        "/type (boolean)",
        "/value 1",
        "}",
        "/parameter-7 {",
        "/key 1936875886",
        "/showInPalette -1",
        "/type (ustring)",
        "/value [ 1",
        "31",
        "]",
        "}",
        "}",
        "}"
    ].join("\n");

    if (app.documents.length == 0) {
        return;
    }


    var destStr = decodeURI(dest.fsName);
    var actionFileDestStr = Folder.desktop + "/MyAction.aia";
    writeFile(actionFileDestStr, actionStr.replace("PUT_FOLDERPATH_CHAR_LENGTH_HERE", destStr.length).replace("PUT_HEX_FOLDERPATH_HERE", destStr.hexEncode()));
    var actionFile = File(actionFileDestStr);
    app.loadAction(actionFile);
    app.doScript("Save My JPEG", "Test");


    //clean up 
    actionFile.remove();
    app.unloadAction("Test", '');
};

main();

 

I have got this a long ago from old thread only. May be it works for you too.

 

Best regards
Charu Rajput
Community Expert
Community Expert
June 27, 2020

Found the reference link for the above answer. Credit goes to person for below link - Its says EPS to JPEG.

https://community.adobe.com/t5/illustrator/eps-to-jpg-export-options-in-300-dpi-illustrator/td-p/9573105?page=1

Best regards