Skip to main content
Inspiring
April 30, 2024
Answered

script to Flatten Transparency

  • April 30, 2024
  • 4 replies
  • 1033 views

Hello, Proficient Expert,

 

I build a new post to discussthis issue about Flatten Transparency,  Is there a better way to solve it with AI,  besides using app.executeMenuCommand('Flatten Transparency')?

 

app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
var pdfOptions = app.preferences.PDFFileOptions;
pdfOptions.pageRangeToOpen = "all"; 
pdfOptions.placeAsLinks = true;
var idoc = app.open(File("~/Desktop/test.pdf")); 
app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;var doc = app.activeDocument;
var pItems = doc.placedItems;
for(var i=pItems.length-1; i>=0; i--){ 
pItems[i].selected = true;
app.executeMenuCommand('Flatten Transparency') ;
}

Correct answer rui huang

below script without pop up a window, have to basic on the preset in the window of 'Flatten Transparency'. if the preset is change , all will be changed, there is risk to proceed pdf file.  whether can make the preset with script ?


app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
var pdfOptions = app.preferences.PDFFileOptions;
pdfOptions.pageRangeToOpen = "all";
pdfOptions.placeAsLinks = true;
var idoc = app.open(File("~/Desktop/test.pdf"));

var doc = app.activeDocument;
var pItems = doc.placedItems;
for(var i=pItems.length-1; i>=0; i--){
pItems[i].selected = true;
app.executeMenuCommand('Flatten Transparency') ;
}

app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;

4 replies

cariley09
Participant
April 30, 2024

I think you know that it carries the risk of preset changes affecting all documents and as currently there's no direct script to set the preset for Flatten Transparency....... you can mitigate risks by specifying the transparency flattening settings programmatically within your script.

 

It involves simple things like you've to define the necessary parameters such as raster resolution and color conversion options to match your desired preset. By setting these parameters in your script, you ensure consistent and controlled flattening without relying on manual presets. You can also explore Adobe's scripting documentation for any updates or alternative approaches to achieve this task more effectively.

pixxxelschubser
Community Expert
Community Expert
April 30, 2024

@cariley09 

who did you actually answer?

pixxxelschubser
Community Expert
Community Expert
April 30, 2024

Untested, but should be possible:

In your Script

Save as PDF with PDFSaveOptions flattenerPreset: string (the name of your preset)

 

Sent from my phone

rui huangAuthor
Inspiring
May 1, 2024

must convert text to outline when open,  because pdf file may be missing font , so will show error char.

Nicky G.
Known Participant
April 30, 2024

I had also asked for help to create a script that imported PDF files into multiple artboards, and then applied a transparency conversion with a preset profile. But no one helped me. Probably no one knows how to do it.

https://community.adobe.com/t5/illustrator-discussions/script-help-import-file-to-artboards-and-flatten-trasparency/m-p/14141439#M383150

 

 

rui huangAuthorCorrect answer
Inspiring
April 30, 2024

below script without pop up a window, have to basic on the preset in the window of 'Flatten Transparency'. if the preset is change , all will be changed, there is risk to proceed pdf file.  whether can make the preset with script ?


app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
var pdfOptions = app.preferences.PDFFileOptions;
pdfOptions.pageRangeToOpen = "all";
pdfOptions.placeAsLinks = true;
var idoc = app.open(File("~/Desktop/test.pdf"));

var doc = app.activeDocument;
var pItems = doc.placedItems;
for(var i=pItems.length-1; i>=0; i--){
pItems[i].selected = true;
app.executeMenuCommand('Flatten Transparency') ;
}

app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;