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

Photoshop Script Import PDF Application.open without dialog

Explorer ,
Sep 02, 2021 Sep 02, 2021

Copy link to clipboard

Copied

I'm working in Photoshop 2021 and writing a script to open a PDF and do some stuff with it.  I'd like to automate the import of multiple files, but when I use app.open() to open the PDF file, I get the "Import PDF" dialog pop up and I have to click OK, no matter what I use in my PDFOpenOptions.   Any way around this popup or is this by design?

TOPICS
Actions and scripting

Views

5.9K

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

correct answers 1 Correct answer

Explorer , Sep 07, 2021 Sep 07, 2021

I ended up using a suggestion by r_bin to use a wsh script that uses sendkeys to photoshop.  It's an ungodly hack but it may end up working.  We will see when we try to automate it with the full data set of 1000s of PDFs.

 

Lesson learned: DialogModes.NO does not really mean no dialogs.

Votes

Translate

Translate
Adobe
Explorer ,
Sep 02, 2021 Sep 02, 2021

Copy link to clipboard

Copied

Also, using app.displayDialogs = DialogModes.NO, prevents the dialog, but the PDF is not opened/imported.

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
Guide ,
Sep 02, 2021 Sep 02, 2021

Copy link to clipboard

Copied

Do your PDFs contain only one page, or are they multi-page documents?

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
Explorer ,
Sep 02, 2021 Sep 02, 2021

Copy link to clipboard

Copied

Single-pagers, all of em

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
Guide ,
Sep 02, 2021 Sep 02, 2021

Copy link to clipboard

Copied

 

openPDF(new File("E:/test single page.pdf"), 300, 8, true, 3302, 2071, false, false, true, 1);

function openPDF(fileObject, resolution, depth, antiAliasing, width, height, constrainProportions, suppressWarnings, reverse, pageNumber) {
    var s2t = stringIDToTypeID;

    (d = new ActionDescriptor()).putEnumerated(s2t("crop"), s2t("cropTo"), s2t("boundingBox"));
    d.putUnitDouble(s2t("resolution"), s2t("densityUnit"), resolution);
    d.putEnumerated(s2t("mode"), s2t("colorSpace"), s2t("RGBColor"));
    d.putInteger(s2t("depth"), depth);
    d.putBoolean(s2t("antiAliasing"), antiAliasing);
    d.putUnitDouble(s2t("width"), s2t("pixelsUnit"), width);
    d.putUnitDouble(s2t("height"), s2t("pixelsUnit"), height);
    d.putBoolean(s2t("constrainProportions"), constrainProportions);
    d.putBoolean(s2t("suppressWarnings"), suppressWarnings);
    d.putBoolean(s2t("reverse"), reverse);
    d.putEnumerated(s2t("selection"), s2t("pdfSelection"), s2t("page"));
    d.putInteger(s2t("pageNumber"), pageNumber);
    (d1 = new ActionDescriptor()).putObject(s2t("as"), s2t("PDFGenericFormat"), d);
    d1.putPath(s2t("target"), fileObject);
    executeAction(s2t("open"), d1, DialogModes.NO);
}

 

* many parameters are optional. For example, you can shorten the code only to passing the path (all other parameters will be received by Photoshop from your last settings during manual export)  

 

openPDF(new File("E:/test single page.pdf"));

function openPDF(fileObject) {
    var s2t = stringIDToTypeID;
    (d = new ActionDescriptor()).putObject(s2t("as"), s2t("PDFGenericFormat"), new ActionDescriptor());
    d.putPath(s2t("target"), fileObject);
    executeAction(s2t("open"), d, DialogModes.NO);
}

 

 

 

 

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
Explorer ,
Sep 02, 2021 Sep 02, 2021

Copy link to clipboard

Copied

I will give that a try: executeAction instead of app.open.  

 

I made my own action to open the file for the moment and I can just run that from my script, but I think using "open" like you are suggesting would be better because it is already parameterized.

 

Thanks much

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
Explorer ,
Sep 03, 2021 Sep 03, 2021

Copy link to clipboard

Copied

Kinda working...  No dialogs on opening, but it opens the pdf as a flat image instead of a 3D pdf.   I tried fooling with the "object", "use3DObjectNumber", and "page" properties, but it still opens as an image.  I would suspect the  "as" set to "PDFGenericFormat", but I made an import action which works great and I can see that "PDFGeneric" is listed as the "As" in the actions window.

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
Guide ,
Sep 03, 2021 Sep 03, 2021

Copy link to clipboard

Copied

Yes, it should be so. This function will rasterize the pdf file. You did not say that a 3D object is embedded in the pdf 🤦

 

can you provide a test fille?

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
Explorer ,
Sep 03, 2021 Sep 03, 2021

Copy link to clipboard

Copied

Whoops!   Sorry, I definitely can't give a test file.  I reckon it would be the same for all 3D PDFs but who knows.

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
Guide ,
Sep 03, 2021 Sep 03, 2021

Copy link to clipboard

Copied

Have you tried just opening the file (using app.open) without specifying PDFOpenOptions?

just app.open (File ('c:/test.pdf')) ?

 

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
Explorer ,
Sep 03, 2021 Sep 03, 2021

Copy link to clipboard

Copied

Just tried it.  Opens as a rasterized image.

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
Guide ,
Sep 03, 2021 Sep 03, 2021

Copy link to clipboard

Copied

I found PDF 3D file. This code opens it, but the windows for creating 3D space will most likely not get rid of.

2021-09-03_22-53-21.png

openPDF(new File("D:\\Downloads\\result.PDF"));

function openPDF(fileObject) {
    var s2t = stringIDToTypeID;

    (d = new ActionDescriptor()).putEnumerated(s2t("selection"), s2t("pdfSelection"), s2t("3dobject"));
    d.putInteger(s2t("page3DNumber"), 1);
    (d1 = new ActionDescriptor()).putObject(s2t("as"), s2t("PDFGenericFormat"), d);
    d1.putPath(s2t("null"), fileObject);
    executeAction(s2t("open"), d1, DialogModes.NO);
}

 

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
LEGEND ,
Sep 03, 2021 Sep 03, 2021

Copy link to clipboard

Copied

It leeds to Photoshop engineers with request to bypass this dialog by scripting 🙂

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
Guide ,
Sep 03, 2021 Sep 03, 2021

Copy link to clipboard

Copied

... it is unlikely that someone will do this

 

Photoshop 3D | Common questions around discontinued 3D features

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
LEGEND ,
Sep 03, 2021 Sep 03, 2021

Copy link to clipboard

Copied

Yes I know. They recommend Substance 3D Designer instead.

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
Explorer ,
Sep 07, 2021 Sep 07, 2021

Copy link to clipboard

Copied

I ended up using a suggestion by r_bin to use a wsh script that uses sendkeys to photoshop.  It's an ungodly hack but it may end up working.  We will see when we try to automate it with the full data set of 1000s of PDFs.

 

Lesson learned: DialogModes.NO does not really mean no dialogs.

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
LEGEND ,
Sep 07, 2021 Sep 07, 2021

Copy link to clipboard

Copied

May you link us to his suggestion?

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
Explorer ,
Sep 07, 2021 Sep 07, 2021

Copy link to clipboard

Copied

Bypass warning prompts?

 

He has other posts refining the idea if you search his posts.

 

Off-topic of this question, what I am finding even easier is extracting the U3D/PRCs via iText.  Photoshop seems to be opening these rather nicely and without dialogs if I specifiy DialogModes.NO.

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
LEGEND ,
Sep 08, 2021 Sep 08, 2021

Copy link to clipboard

Copied

LATEST

U3D/PRCs works with no dialog maybe because of: Unable to convert 3D files to PDFs

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
LEGEND ,
Sep 02, 2021 Sep 02, 2021

Copy link to clipboard

Copied

Single page PDF's opens for me with no dialog without using script, so why not for the user?

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
Explorer ,
Sep 02, 2021 Sep 02, 2021

Copy link to clipboard

Copied

Umm idk bud, but it definitely does for me.  Using file open or app.open ().  The window pop up header has the title "Import PDF".  It has a bunch of the options for I forget like color mode and crop window or something I can't remember I'm not there right now.

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
LEGEND ,
Sep 02, 2021 Sep 02, 2021

Copy link to clipboard

Copied

Save some small .psd document as .pdf and open it to see whether you have a dialog for?

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
Explorer ,
Sep 02, 2021 Sep 02, 2021

Copy link to clipboard

Copied

Yeah I'm not sure that that would really help with my situation even if it didn't. I definitely get a pop up. I'm definitely trying to suppress it. I definitely can't change all my source files to be a different format.

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
LEGEND ,
Sep 02, 2021 Sep 02, 2021

Copy link to clipboard

Copied

I don't understand. Did you do this test or not?

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
Guide ,
Sep 02, 2021 Sep 02, 2021

Copy link to clipboard

Copied

I have met such problem in the past. I did not try to understand it in detail, but it seemed to me that the problem was related to an incomplete set of required metadata fields inside the file. At the same time, such files were opened without problems through the action manager.

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