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

Need Help in Scripting

New Here ,
Mar 25, 2025 Mar 25, 2025

Hello @m1b ,

I need some help with a script. Could you please assist me?

Is there any scripting possibility to adjust this dialog box in Photoshop?

TOPICS
Actions and scripting , Windows
355
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 2 Correct answers

Community Expert , Mar 26, 2025 Mar 26, 2025

@punit_9859 â€“ Try this script and let me know how you go:

 

/*
Rasterize to Variable Resolution Based on PDF Page Size in Inches.jsx
Stephen Marsh
v1.0, 26th March 2025
https://community.adobe.com/t5/photoshop-ecosystem-discussions/need-help-in-scripting/td-p/15232063
*/

#target photoshop

// Open a dialog to select the PDF file
var thePDF = File.openDialog("Select a PDF file to rasterize");

if (thePDF !== null) {

    // Get the file dimensions
    var pdfOpenOptions = new PDFOpenOptions();
 
...
Translate
Community Expert , Mar 27, 2025 Mar 27, 2025

For PDF files larger than 200 inches, the Photoshop interface will default to 200 and you will have to manually override this with the desired width, such as 272 in @ 72 ppi. Scripting will have the same limitation with the current script code. I'll see if I can find another workable alternative solution, as my first idea also hits the limit of 200, although it can be made larger if the required size is known.

Translate
Community Expert ,
Mar 25, 2025 Mar 25, 2025

@punit_9859 

 

A script can't adjust a compiled program GUI.

 

It's much easier to script without a graphical user interface, just using basic system dialogs to select files or folders etc.

 

If you want a different GUI, you must recreate the entire interface and associated functions and logic in either legacy ExtendScript or UXP.

 

Perhaps if you posted in more detail, step-by-step what you are trying to do... Or markup a screenshot showing what you want to change.

 

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
New Here ,
Mar 25, 2025 Mar 25, 2025

Thank you for your response.
Yes Sure, @Stephen Marsh 

Basically, I want to create a script that sets a specific DPI based on the image size:

  • 1 inch to 12 inches → 600 DPI

  • 13 inches to 24 inches → 300 DPI

  • 25 inches to 120 inches → 125 DPI

  • More than 120 inches → 72 DPI

Would it be possible to achieve this through a script?

 

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 ,
Mar 26, 2025 Mar 26, 2025
quote

Thank you for your response.
Yes Sure, Stephen Marsh 

Basically, I want to create a script that sets a specific DPI based on the image size:

  • 1 inch to 12 inches → 600 DPI

  • 13 inches to 24 inches → 300 DPI

  • 25 inches to 120 inches → 125 DPI

  • More than 120 inches → 72 DPI

Would it be possible to achieve this through a script?

 


By punit_9859

 

* What is the factor that determines the size in inches for the resolution required (i.e. 1 inch to 12 inches)? Is this width, height, or whichever of the two is larger?

 

* Are these Photoshop PDF files (raster) or are they Generic PDF files, which could contain vectors and rasters?

 

* I presume that you wish to retain the physical print size of the PDF at the required resolution. So if the original image was 8 inches wide, then it should be 8 inches wide @ 600ppi (not dpi) when rasterized. Is that correct?

 

* Are you only rasterizing the first page, or will there be a fixed or variable quantity of multiple pages being rasterized?

 

There are challenges with your request due to limitations with PDFOpenOptions or Action Manager code... The biggest issue is programmatically getting the width or height of the PDF before rasterizing. PDF uses PostScript Points as the internal unit of measure, which is 1/72 inch, so conversions aren't difficult. Within Photoshop, one may have to first rasterize the PDF to get the size, then close and then reopen again with the known size. Or you could try first reading the PDF as binary data and using a regex to find the native size... But what size, page 1, another page, which PDF page box etc?

 

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
New Here ,
Mar 26, 2025 Mar 26, 2025

Hello @Stephen Marsh ,

I want to automate the process so that when I open a PDF file, the Import PDF dialog box automatically sets the resolution based on the following size chart:

  • 1 to 12 inches → 600 DPI

  • 13 to 24 inches → 300 DPI

  • 25 to 120 inches → 125 DPI

  • More than 120 inches → 72 DPI

The script should determine the larger value between height and width and apply the appropriate DPI setting accordingly.

Like I open a pdf using a script and in the import PDF dialog box set the DPI as per chart.


in the Size it dose't matter height ot width its read both and count whichever of the two who is larger.

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
New Here ,
Mar 26, 2025 Mar 26, 2025

also need help in open 200+ inch pdf without changeing their sizes with script

 

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 ,
Mar 26, 2025 Mar 26, 2025

Well that's one question answered!

 

How many pages does the PDF file contain?

 

1 page or more? If more, is it a fixed amount, always 5 pages, or does this vary between documents?

 

What PDF page bounding box should be used for cropping? Media box or something else?

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
New Here ,
Mar 26, 2025 Mar 26, 2025

Only one page

 

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 ,
Mar 26, 2025 Mar 26, 2025
quote

also need help in open 200+ inch pdf without changeing their sizes with script

 


By punit_9859

 

I have the script completed for up to 125+ inches at the various required resolutions based on your nominated sizes, however, this additional new requirement for 200 inches confuses me.

 

I'm not understanding... What does this mean? What problems are faced? 200 inches is greater than 125 inches, so the 72 PPI resolution value would already cover it.


200 inches @ 72 PPI would be 14,400 px, which is well under the 32,000 px size where I'd expect issues when opening a PDF.

 

What resolution should something 200+ inches be if not 72 PPI?

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
New Here ,
Mar 26, 2025 Mar 26, 2025

@Stephen Marsh ,

I faced an issue:

For PDFs over 200 inches, I need 72 DPI, but when I open a PDF larger than 200 inches, the Import PDF dialog automatically limits the size to 200 inches.

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 ,
Mar 26, 2025 Mar 26, 2025

@punit_9859 â€“ Try this script and let me know how you go:

 

/*
Rasterize to Variable Resolution Based on PDF Page Size in Inches.jsx
Stephen Marsh
v1.0, 26th March 2025
https://community.adobe.com/t5/photoshop-ecosystem-discussions/need-help-in-scripting/td-p/15232063
*/

#target photoshop

// Open a dialog to select the PDF file
var thePDF = File.openDialog("Select a PDF file to rasterize");

if (thePDF !== null) {

    // Get the file dimensions
    var pdfOpenOptions = new PDFOpenOptions();
    pdfOpenOptions.antiAlias = true;
    pdfOpenOptions.mode = OpenDocumentMode.GRAYSCALE; // Set to grayscale for speed
    pdfOpenOptions.resolution = 2; // Low res for speed
    pdfOpenOptions.page = 1; // First page only
    pdfOpenOptions.cropPage = CropToType.MEDIABOX; // MEDIABOX | CROPBOX | BLEEDBOX | TRIMBOX | ARTBOX
    app.open(thePDF, pdfOpenOptions);

    // Get the doc width and height in inches
    var docWidthInches = (app.activeDocument.width.as("inches")).toFixed(2);
    var docHeightInches = (app.activeDocument.height.as("inches")).toFixed(2);

    // Close the doc without saving
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    // Determine the greater value between width and height
    var maxDimensionInches = Math.max(docWidthInches, docHeightInches);

    // Set the resolution based on the greater value
    var resolution;
    if (maxDimensionInches < 12) {
        resolution = 600;
    } else if (maxDimensionInches >= 12.01 && maxDimensionInches <= 24) {
        resolution = 300;
    } else if (maxDimensionInches >= 24.01 && maxDimensionInches <= 120) {
        resolution = 125;
    } else {
        resolution = 72;
    }

    // Re-open the PDF as a new doc in RGB mode with the determined resolution
    pdfOpenOptions.mode = OpenDocumentMode.RGB;
    pdfOpenOptions.resolution = resolution;
    app.open(thePDF, pdfOpenOptions);

    // Flatten the image to remove transparency and layers
    app.activeDocument.flatten();

    /*
    // New layer from Background
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putProperty(s2t("layer"), s2t("background"));
    descriptor.putReference(s2t("null"), reference);
    descriptor.putObject(s2t("to"), s2t("layer"), descriptor2);
    executeAction(s2t("set"), descriptor, DialogModes.NO);
    */

} else {
    alert("Script cancelled!");
}

 

  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save as a plain text format file – .txt
  5. Rename the saved file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run (see below)

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

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
New Here ,
Mar 26, 2025 Mar 26, 2025

@Stephen Marsh ,

The script works perfectly for files under 200 inches, but for files above 200 inches, it automatically limits the maximum size to 200 inches.

For reference, I have attached a file with dimensions 272 inches × 152 inches.

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 ,
Mar 26, 2025 Mar 26, 2025

Scripts can't change how Photoshop works, what it's limitations are.

 

I have an alternative method which might work for these large dimensions. I'll come back to you when I have time.

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 ,
Mar 27, 2025 Mar 27, 2025

For PDF files larger than 200 inches, the Photoshop interface will default to 200 and you will have to manually override this with the desired width, such as 272 in @ 72 ppi. Scripting will have the same limitation with the current script code. I'll see if I can find another workable alternative solution, as my first idea also hits the limit of 200, although it can be made larger if the required size is known.

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
New Here ,
Mar 27, 2025 Mar 27, 2025

okay 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
Community Expert ,
Mar 27, 2025 Mar 27, 2025

@punit_9859 

 

This v2 script uses a different method to get the PDF page size, it works with your sample PDF but fails with some other PDF files that lack the required information. If you get an error that the page size can't be determined, use the previous v1 script.

 

I hope to rework this, but it will have to do for now:

 

Back to the drawing board. Reflecting on the challenges and your feedback, I think that it is best and safest to process files 200 inches or larger manually. I have replaced the previous 2.0 code with the new v2.1 code as it wasn't performing as expected.

 

/*
Rasterize to Variable Resolution Based on PDF Page Size in Inches.jsx
Stephen Marsh
v2.1, 26th March 2025
https://community.adobe.com/t5/photoshop-ecosystem-discussions/need-help-in-scripting/td-p/15232063
*/

#target photoshop

// Open a dialog to select the PDF file
var thePDF = File.openDialog("Select a PDF file to rasterize");

if (thePDF !== null) {

    // Get the file dimensions
    var pdfOpenOptions = new PDFOpenOptions();
    pdfOpenOptions.antiAlias = true;
    pdfOpenOptions.mode = OpenDocumentMode.GRAYSCALE; // Set to grayscale for speed
    pdfOpenOptions.resolution = 2; // Low res for speed
    pdfOpenOptions.page = 1; // First page only
    pdfOpenOptions.cropPage = CropToType.MEDIABOX; // MEDIABOX | CROPBOX | BLEEDBOX | TRIMBOX | ARTBOX
    app.open(thePDF, pdfOpenOptions);

    // Get the doc width and height in inches
    var docWidthInches = (app.activeDocument.width.as("inches")).toFixed(2);
    var docHeightInches = (app.activeDocument.height.as("inches")).toFixed(2);

    // Close the doc without saving
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

    // Determine the greater value between width and height
    var maxDimensionInches = Math.max(docWidthInches, docHeightInches);

    // Set the resolution based on the greater value
    var resolution;
    if (maxDimensionInches <= 12) {
        resolution = 600;
    } else if (maxDimensionInches >= 12.01 && maxDimensionInches <= 24) {
        resolution = 300;
    } else if (maxDimensionInches >= 24.01 && maxDimensionInches <= 120) {
        resolution = 125;
    } else if (maxDimensionInches <= 199.99) {
        resolution = 72;
    } else {
        alert("Process this oversize PDF manually.");
        throw new Error("Process this oversize PDF manually.");
    }

    // Re-open the PDF as a new doc in RGB mode with the determined resolution
    pdfOpenOptions.mode = OpenDocumentMode.RGB;
    pdfOpenOptions.resolution = resolution;
    app.open(thePDF, pdfOpenOptions);

    // Flatten the image to remove transparency and layers
    app.activeDocument.flatten();

    /*
    // New layer from Background
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putProperty(s2t("layer"), s2t("background"));
    descriptor.putReference(s2t("null"), reference);
    descriptor.putObject(s2t("to"), s2t("layer"), descriptor2);
    executeAction(s2t("set"), descriptor, DialogModes.NO);
    */

} else {
    alert("Script cancelled!");
}

 

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
New Here ,
Mar 27, 2025 Mar 27, 2025

@Stephen Marsh ,

I ran the script but encountered some issues. When using the script, the file does not open at its accurate size in Photoshop. For reference, I will attach a screenshot showing the original file size and the size after opening via the script.

Additionally, the script always opens the file in RGB mode. If possible, I would like the script to open the file in its original color mode— for example, if the file is in CMYK, it should open in CMYK, and if it is in RGB, it should open in 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
Community Expert ,
Mar 27, 2025 Mar 27, 2025

Are all of the files from the same source, Adobe Illustrator?

 

Why do you need to rasterize?

 

Have you tried rasterizing the PDF in either Illustrator or Acrobat Pro?

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
New Here ,
Mar 27, 2025 Mar 27, 2025

@Stephen Marsh ,

Not all files come from the same source. The reason for rasterizing is to allow the printing department to add crop marks or make other necessary adjustments. Additionally, if they need to add or remove crop marks or make further modifications, they always use Adobe Photoshop. Therefore, I always prefer to open PDFs directly in Adobe Photoshop.

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

@punit_9859 

 

Back to the drawing board. Reflecting on the challenges and your feedback, I think that it is best and safest to process files 200 inches or larger manually. I have replaced the previous 2.0 code with the new v2.1 code as it wasn't performing as expected. 

 

I'm going to have to take a break on this, good luck!

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

Thank You @Stephen Marsh !

 

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