[Not working?] FlattenerPreset - ExtendScript for Indesign

New Here ,
Mar 28, 2021 Mar 28, 2021

Copy link to clipboard

Copied

Hello!

 

I am writing a script for an automation process. As of now I have 2 scripts, which, when the template is fixed and updated with needs of automation, will be merged into 1 script. My idea is that, I want as few stuff as possible prepared in InDesign and I want stuff to be coded instead (reduces human-error possibility).

 

However,

I am struggling with figuring out flattenerPreset.

I tried:

- app.open("Path").flattenerPreset

- app.activeDocument.flattenerPreset

- app.flattenerPreset

In any way I tried using it, I keep getting same error, that "Object does not support the property or method flattenerPreset". Any idea how to write that part of code correctly? Cos all Adobe Indesign ESJS docs I found say, that app is the superclass for flattenerPreset.

 

const drivePath = "E:";
const finalPath = "\\Folder1\\Folder2\\Folder3\\";
const exportPath = "\\FolderA\\FolderB\\";
const projFileExt = ".indd";
const pdfFileExt = ".pdf"

var dmArray = ["element_1", "element_2"];


for (var i = 0; i < dmArray.length; i++) {
    var projFile = app.open(drivePath + finalPath + dmArray[i] + "\\" + dmArray[i] + projFileExt);
    var exportFolder = new Folder (drivePath + exportPath + dmArray[i]);
    var pdfFile = File (exportFolder + "\\" + dmArray[i] + pdfFileExt);
    var pdfPreset = app.pdfExportPresets.item("voucher_dtp");
    var acDoc = app.activeDocument

    projFile;

    with(aDoc.flattenerPreset) {
        item(0).rasterVectorBalance = 100;
        }

    if (!exportFolder.exists){
    exportFolder.create();
    };

    aDoc.exportFile (
        ExportFormat.PDF_TYPE,
        pdfFile,
        false,
        pdfPreset
    );

    acDoc.close(SaveOptions.NO)
}

 

Additionally, if someone could tell me how to code "convertAllStrokesToOutlines", I'd be thankful. Should it look like the below part? Given, we manage to find the correct superclass for flattenerPreset.

 

    with(app.flattenerPreset) {
        convertAllStrokesToOutlines = true;
        }

 

Some links:

Adobe Indesign CC 16.1: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#FlattenerPreset.html

Adobe Indesign CS6 8.0: http://jongware.mit.edu/idcs6js/pc_FlattenerPreset.html

Adobe Indesign CS6 8.0: https://documentation.help/InDesign-Server-CS6/pc_FlattenerPreset.html

Old reply about similar topic for CS3: https://community.adobe.com/t5/indesign/cs3-js-a-little-help-setting-flattener-prefs/td-p/1130458

TOPICS
Scripting

Views

149

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 ,
Mar 28, 2021 Mar 28, 2021

Copy link to clipboard

Copied

You can get an existing flattener preset via itemByName like this (note the flattenerPreset list is a property of the application not the document):

 

 

var fp = app.flattenerPresets.itemByName("[High Resolution]")

$.writeln("Properties:" + fp.properties.toSource()) 
//returns: Properties:({name:"[High Resolution]", rasterVectorBalance:100, lineArtAndTextResolution:1200, 
//gradientAndMeshResolution:300, clipComplexRegions:true, convertAllStrokesToOutlines:false, 
//convertAllTextToOutlines:false, id:141, label:"", parent:resolve("/"), index:2})

 

 

 

Or you can create one if it doesn’t already exist and then edit its properties:

 

 

var newfp = makeNewFlattener("MyFlattener");
newfp.properties = {lineArtAndTextResolution:1200, convertAllStrokesToOutlines:true}



/**
* Makes a new Flattener Preset 
*  preset name 
*  the new flattener preset 
*/
function makeNewFlattener(n){
    var nfp;
    try {
        app.flattenerPresets.add({name:n});
    }catch(e) {
        nfp = app.flattenerPresets.itemByName(n)
    } 
    return app.flattenerPresets.itemByName(n);
}

 

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
New Here ,
Mar 28, 2021 Mar 28, 2021

Copy link to clipboard

Copied

Thank you a lot.

 

I'll test your solution later today and I'll make sure to let you know, if it worked 🙂

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
New Here ,
Mar 28, 2021 Mar 28, 2021

Copy link to clipboard

Copied

I happened into another issue:

 

1) I create a flattener preset by script or manually (either way, it's created and there, but I was just testing both ways)

2) I select "Convert all text to outlines"

3) I go to export window and select .pdf

4) In advanced, I choose my flattener preset

5) The .pdf still has text in it, not outlines

 

Do you happen to know the solution?

 

As for the code you sent - I didn't exactly do what you said, but your reply helped a lot regardless - it guided me into the right direction. Thank you 🙂

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 ,
Mar 29, 2021 Mar 29, 2021

Copy link to clipboard

Copied

I didn't exactly do what you said

Do you mean you got an error, or the preset wasn’t created? Can you show your code? 

 

5) The .pdf still has text in it, not outlines

Are there transparent objects on all of the spreads? You wouldn’t get outines unless there is transparency to flatten. Can you show your preset settings? In your first post you are setting convertAllStrokesToOutlines = true; but to get text outlines you would need to set convertAllTextToOutlines.

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 ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

LATEST

Hi together,

also note that there is:

 

app.exportPresets()

first argument can be ExportPresetFormat.FLATTENER_PRESETS_FORMAT,

second argument can be the flattener preset file.

 

app.importFile()

first argument can be ExportPresetFormat.FLATTENER_PRESETS_FORMAT,

second argument can be the flattener preset file.

 

 

Details:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Application.html#d1e42253__d1e46557

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Application.html#d1e42253__d1e47259

 

Regards,
Uwe Laubender

( ACP )

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