• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to use a script to retrieve existing ADOBE PDF presets in Photoshop using a dropdown menu?

Contributor ,
Jun 29, 2023 Jun 29, 2023

Copy link to clipboard

Copied

I am working on a script to export layers to PDF, but I have encountered an issue. This is something I already know how to do in InDesign and Illustrator. How to use a script to retrieve existing ADOBE PDF presets in Photoshop using a dropdown menu? I kindly request assistance from friends.

For example, the method to retrieve presets in Illustrator is as follows.

var presetNames = app.PDFPresetsList;
var presetList = presetGroup.add("dropdownlist", [0, 0, 220, 25]);

for (var i = 0; i < presetNames.length; i++) {
  presetList.add("item", presetNames[i]);
}

Does Photoshop have a similar method?

 

TOPICS
Actions and scripting

Views

647

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 Expert ,
Jun 29, 2023 Jun 29, 2023

Copy link to clipboard

Copied

No, not according to the documentation (»photoshop-cc-javascript-ref-2019.pdf«).

But as far as I know the pdf presets are not application-specific so you should be able to use the list from Indesign or Illustrator. (Which you should be able to retrieve via BridgeTalk.)

Or »simply« get the joboptions-files’ names (»~/Library/Application Support/Adobe/Adobe PDF/Settings«). 

Votes

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
Contributor ,
Jun 30, 2023 Jun 30, 2023

Copy link to clipboard

Copied

BridgeTalk can be annoying as it opens InDesign simultaneously. This method is not very user-friendly!

Votes

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 Expert ,
Jul 02, 2023 Jul 02, 2023

Copy link to clipboard

Copied

BridgeTalk can be annoying as it opens InDesign simultaneously. This method is not very user-friendly!

 

Hi @Aprking , Not sure if this helps, but you could export a PSD’s layers from within InDesign without ever opening Photoshop. The graphicLayerOptions.graphicLayers collection lets you turn a placed .PSD’s layer visibility on and off for an export. A script could create a document, place the PSD, size the page to the PSD, then loop through the image layers and Export each to PDF.

 

//From InDesign a selected PSD image with object layers
var gl = app.activeDocument.selection[0].graphicLayerOptions.graphicLayers.everyItem().getElements();

for (var i = 0; i < gl.length; i++){
   $.writeln(gl[i].name + "   Visible: " + gl[i].currentVisibility)
};   

 

 

Votes

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 ,
Jun 30, 2023 Jun 30, 2023

Copy link to clipboard

Copied

@Aprking,

As @c.pfaffenbichler has already mentioned, you can get the joboptions-files’ names (»~/Library/Application Support/Adobe/Adobe PDF/Settings«).  but note that this will only be any "Custom pdf export presets" that you've created or loaded and not any of the built in ones.

Please see the working snippet below.

var myAdobePDF_Presets = Folder("~/Library/Application Support/Adobe/Adobe PDF/Settings");
var myCustomPresets = myAdobePDF_Presets.getFiles();

var myPresets = [];
for(var i = 0; i < myCustomPresets.length; i++){
    myPresets.push(myCustomPresets[i].name.replace(/%20/g, " ").slice(0, -11))
}

myPresets.unshift("- Select Preset -");
 
var myWin = new Window('dialog', 'PDF Export Presets');
myWin.orientation = 'row';
with(myWin){
    myWin.sText = add('statictext', undefined, 'Select PDF Export preset:');
    myWin.myPDFExport = add('dropdownlist',undefined,undefined,{items:myPresets});
    myWin.myPDFExport.selection = 0;
    myWin.btnOK = add('button', undefined, 'OK');
    };
myWin.center();
var myWindow = myWin.show();

Regards,

Mike

Votes

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 Expert ,
Jun 30, 2023 Jun 30, 2023

Copy link to clipboard

Copied

quote

but note that this will only be any "Custom pdf export presets" that you've created or loaded and not any of the built in ones.

Good point; makes me wonder where the default joboptions are stored. 

But if they are available by default anyway I suppose one could hard-code them into the Script. 

Votes

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 ,
Jun 30, 2023 Jun 30, 2023

Copy link to clipboard

Copied

@c.pfaffenbichler 

I couldn't find where the default joboptions are stored, they're probably buried somewhere in a preference file.

Below is an updated snippet with the default joboptions hard codded in to the script.

 

var myAdobePDF_Presets = Folder("~/Library/Application Support/Adobe/Adobe PDF/Settings");
var myCustomPresets = myAdobePDF_Presets.getFiles();
var adobeBuiltInPDF_Presets = ["[High Quality Print]", "[PDF/X-1A:2001]", "[PDF/X-3:2002]","[PDF/X-4:2008]", "[Press Quality]", "[Smallest File Size]"];

var myPresets = [];
for(var i = 0; i < myCustomPresets.length; i++){
    myPresets.push(myCustomPresets[i].name.replace(/%20/g, " ").slice(0, -11));
}

var mergedPresets = adobeBuiltInPDF_Presets.concat(myPresets);

mergedPresets.unshift("- Select Preset -");
 
var myWin = new Window('dialog', 'PDF Export Presets');
myWin.orientation = 'row';
with(myWin){
    myWin.sText = add('statictext', undefined, 'Select PDF Export preset:');
    myWin.myPDFExport = add('dropdownlist',undefined,undefined,{items:mergedPresets});
    myWin.myPDFExport.selection = 0;
    myWin.btnOK = add('button', undefined, 'OK');
    };
myWin.center();
var myWindow = myWin.show();

 

Regards,

Mike

Votes

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 Expert ,
Jul 01, 2023 Jul 01, 2023

Copy link to clipboard

Copied

The default joboptions are contained within the .app bundle on macOS. It is probably also found near .exe on Windows.

/Applications/Adobe Photoshop 2023/Adobe Photoshop 2023.app/Contents/Required/PDF/Settings

presets.png

Votes

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 Expert ,
Jul 02, 2023 Jul 02, 2023

Copy link to clipboard

Copied

Neat! 

Votes

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
People's Champ ,
Jul 02, 2023 Jul 02, 2023

Copy link to clipboard

Copied

It seems to me that the names of the files and the names of the presets in the saveAsPDF dialog are slightly different.

Votes

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 Expert ,
Jul 02, 2023 Jul 02, 2023

Copy link to clipboard

Copied

LATEST

It seems to have the translated names in the nearby Translations folder. But I don’t know how to parse zdct, and I am not sure where the English names come from.

translation.png

How about looking in your computer’s application support folder instead of user? Does this match the English display name?

/Library/Application Support/Adobe/Adobe PDF/Settings

settings.png

Votes

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
Contributor ,
Jun 30, 2023 Jun 30, 2023

Copy link to clipboard

Copied

I have written a script in Photoshop to retrieve ADOBE PDF presets, but it is only compatible with Windows 10 and above. However, the same approach should work for adapting it to Mac. 

/*
* #target Photoshop
* Author: Aprking
* Contact: aprking@hotmail.com
*/

if (BridgeTalk.appName == "photoshop") {
  var userName = getCurrentUsername();
}

function getCurrentUsername() {
  var userName = $.getenv("USERNAME");
  if (!userName) {
    userName = $.getenv("USER");
  }
  return userName;
}

var dialog = new Window("dialog");
dialog.text = "Select PDF Preset";
dialog.orientation = "column";
dialog.alignChildren = "left";

var presetsDropdown = dialog.add("dropdownlist");
presetsDropdown.preferredSize.width = 200;

var loadButton = dialog.add("button", undefined, "Load");
loadButton.onClick = loadSelectedPreset;

var pdfPresets = getPDFPresets();
for (var i = 0; i < pdfPresets.length; i++) {
  var presetName = pdfPresets[i];
  presetsDropdown.add("item", presetName);
}

presetsDropdown.selection = presetsDropdown.items[1];
dialog.show();

function getPDFPresets() {
  var presetFolderPath1 = "C:\\Users\\" + userName + "\\AppData\\Roaming\\Adobe\\Adobe PDF\\Settings";
  var presetFolderPath2 = "C:\\ProgramData\\Adobe\\Adobe PDF\\Settings";
  var folder1 = new Folder(presetFolderPath1);
  var folder2 = new Folder(presetFolderPath2);
  var files1 = folder1.getFiles("*.joboptions");
  var files2 = folder2.getFiles("*.joboptions");

  var presets = [];
  for (var i = 0; i < files1.length; i++) {
    var file1 = files1[i];
    var name1 = file1.name.replace(/\.joboptions$/, "");
    presets.push(decodeURIComponent(name1));
  }
  for (var i = 0; i < files2.length; i++) {
    var file2 = files2[i];
    var name2 = file2.name.replace(/\.joboptions$/, "");
    presets.push(decodeURIComponent(name2));
  }

  return presets;
}

function loadSelectedPreset() {
  var selectedIndex = presetsDropdown.selection.index;
  var selectedPreset = pdfPresets[selectedIndex];
  alert("Loaded PDF Preset: " + selectedPreset);
}

Votes

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