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

PDFOpenOptions issue with open(file, options)

Guest
May 17, 2011 May 17, 2011

Hi guys,

I have a script to open JPGs and now I need to adapt it to open PDFs.

I'm getting a "wrong type of enumerated value" error exactly because of the way I'm working the PDFOpenOptions (line "open(fileList, pdfOpenOptions);").

I found quite a few scripts that define pdf open options just like I did, but in all of them the root path was hard coded (I need it dynamic).

So, where am I going wrong? Too much time on it, can't see errors anymore... (mac, cs4)

#target photoshop

app.preferences.rulerUnits = Units.PIXELS;

app.displayDialogs = DialogModes.NO;

app.backgroundColor.rgb.red = 255;

app.backgroundColor.rgb.green = 255;

app.backgroundColor.rgb.blue = 255;

var pdfOpenOptions = new PDFOpenOptions();

pdfOpenOptions.antiAlias = true;

pdfOpenOptions.mode = DocumentMode.RGB;

pdfOpenOptions.bitsPerChannel = BitsPerChannelType.EIGHT;

pdfOpenOptions.resolution = 72;

pdfOpenOptions.supressWarnings = true;

pdfOpenOptions.cropPage = CropToType.TRIMBOX;

var fileList = File.openDialog("Select files to batch",true);

if (fileList != null) {

     for (var i in fileList) {

          if (fileList instanceof File && fileList.hidden == false) {

               open(fileList, pdfOpenOptions);

          }

     }

alert("Done");

}

else {

     alert("No files selected");

}

Thanks in advance!

TOPICS
Actions and scripting
2.9K
Translate
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

Guide , May 17, 2011 May 17, 2011

Replace 'DocumentMode.RGB' with 'OpenDocumentMode.RGB'

Translate
Adobe
Guide ,
May 17, 2011 May 17, 2011

Replace 'DocumentMode.RGB' with 'OpenDocumentMode.RGB'

Translate
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
Guest
May 17, 2011 May 17, 2011

Bingo! Thanks!!!

Translate
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
Guest
May 17, 2011 May 17, 2011

Cool!

I had to figure some other things out like extracting the path from openDialog
which I didn't find anywhere else.

So it's finely time to share a decent and commented script (with the invaluable
help of Muppet Mark, thanks man!):

//This script is set to open pdf files,

//make 256x256px JPG duplicates,

//create a folder named zJPGs relative to the doc's path

//and save the files there

//Gustavo Soares,

//with the great help of Muppet Mark and many others

#target photoshop

//set units to pixels

app.preferences.rulerUnits = Units.PIXELS;

//avoid displaying dialog boxes

app.displayDialogs = DialogModes.NO;

//set background color to white

app.backgroundColor.rgb.red = 255;

app.backgroundColor.rgb.green = 255;

app.backgroundColor.rgb.blue = 255;

//define the pdf options for opening the document

var pdfOpenOptions = new PDFOpenOptions();

pdfOpenOptions.antiAlias = true;

pdfOpenOptions.mode = OpenDocumentMode.RGB;

pdfOpenOptions.bitsPerChannel = BitsPerChannelType.EIGHT;

pdfOpenOptions.resolution = 72;

pdfOpenOptions.supressWarnings = true;

pdfOpenOptions.cropPage = CropToType.TRIMBOX;

//pdfOpenOptions.page = 1

//Select files to batch ('true' is for aloowing multiple seleciont)

var fileList = File.openDialog("Select files to batch", true);

//Returns the dynamic path from the openDialog –

//there's certainly a better way for doing this

var fullPath = fileList[0];

var fullPathTemp = fullPath.fsName;

var sliceIndex = fullPathTemp.lastIndexOf ("/");

var docPath = fullPathTemp.slice(0, sliceIndex); //'0' means the beginning of the string

//Read the functions below to understand the loop

if (fileList != null) {

     for (var i in fileList) {

          if (fileList instanceof File && fileList.hidden == false) {

               open(fileList, pdfOpenOptions);

               jpg256();

               app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

          }

     }

alert("Done");

}

else {

     alert("No files selected");

}

//––––––––––––––––––––

//Functions start here

//––––––––––––––––––––

function jpg256() {     

     

     //make a 256 x 256px image of the original document

     var myDoc = app.activeDocument

     var docName = myDoc.name;

     //can use this for opening files with extension

     //var docNameChange = docName.slice(0, -4);

     var myNewDocName = docName + ".jpg";

     var myNewDoc = myDoc.duplicate(myNewDocName, true);

     var width = myNewDoc.width;

     var height = myNewDoc.height;

     

     //resize

     if (height >= width) {

          myNewDoc.resizeImage (null, 256, 72, ResampleMethod.BICUBICSHARPER);

          // 'null' resizes proportionally

          myNewDoc.resizeCanvas (256, 256, AnchorPosition.MIDDLECENTER);

     }

     else {

          myNewDoc.resizeImage (256, null, 72, ResampleMethod.BICUBICSHARPER);

          // 'null' resizes proportionally

          myNewDoc.resizeCanvas (256, 256, AnchorPosition.MIDDLECENTER);

     }

     

     //save the file in a folder named 256x256

     //check if it exists, if it doesn't then create

     var jpegOptions = new JPEGSaveOptions();

     jpegOptions.quality = 7;

     

     var folder256 = docPath + "/zJPGs";

     if (Folder(folder256).exists) {

          save256();

     }

     else {

          var fldr = new Folder(folder256);

          fldr.create();

          save256();

     }

     function save256() {

          myNewDoc.saveAs(new File(folder256), jpegOptions);

          myNewDoc.close(SaveOptions.DONOTSAVECHANGES);

     }

}

Translate
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 ,
Oct 07, 2016 Oct 07, 2016

I wanted to use the dynamic file opening code you wrote in one of my own scripts. However, I also need to open EPS, TIff, PSD, PNG, and jpeg files.

There is something in the code that disallows or doesn't specify whcih files can be opened.

Could you explain or give me a sample to get me started in the right direction?

Thanks for your consideration.

Translate
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
Explorer ,
Sep 17, 2025 Sep 17, 2025

One Edit to the loop for it to work, adding [i]

if (fileList != null) {
     for (var i in fileList) {
          if (fileList instanceof File && fileList.hidden == false) {
               open(fileList, pdfOpenOptions);
          }
     }
Translate
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 ,
Sep 17, 2025 Sep 17, 2025
LATEST

@_wckdTall_ 

 

Thanks for posting/updating. When Adobe changed the forum software it broke the variables in the old code.

Translate
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