• 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

4.5K

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

Copy link to clipboard

Copied

PDF seems to be an Adobe file format and there seems to be more then a single PDF file format.  There seems to be Adobe an Acrobat  document PDF file format and Photoshop layered document PDF file format. .   Photoshop PDF File format seen to open in Photoshop  through Photoshop's File Open without an additional Import PDF Dialog.  Opening An  Acrobat single Page document through Photoshop Open File dialog I see Photoshop Open an Import PDF Dialog.  Photoshop Handle Acrobat PDF File formats differently than it handles its own PDF File format.

Capture.jpg

My script still sees to open small Acrobat multiple paged PDF documents with only the File open dialog the Import PDF  dialog is not seen by the user The PDF Page Documents are stacked into a single Photoshop document and the transparent pages filled with white.  The opened Pages documents are closed.  However they Raster Layer no text  layers exists.

image.png

JJMack

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

What's the reason you tell me that? 😛

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

Copy link to clipboard

Copied

I did not read through  this thread  I create a script  years ago the open a pdf pages in Photoshop It does not have a Script Dialog but does have a system  open  file selection dialog so you can select the PDF to open its pages. I believe it  creates a document with the PDF pages stacked on top of each other. It bypasses the PDF Import dialog. Have not used it in years.

 

/* ==========================================================
// 2017  John J. McAssey (JJMack) 
// Stack the open Document Visible layer composite into a new 300 DPI document
// This script is supplied as is. It is provided as freeware. 
// The author accepts no liability for any problems arising from its use.
// ======================================================= */
// enable double-clicking from Mac Finder or Windows Explorer
#target photoshop // this command only works in Photoshop CS2 and higher
// bring application forward for double-click events
app.bringToFront();

if (documents.length >= 2) { 
	app.togglePalettes();											// toggle off palettes so Photoshop will not need to update them
	stackpages();												    // Photosho document can be different when oneo via UI
}
else {
	var theFile = File.openDialog("Select your PDF file", "Select:*.pdf");  
	app.displayDialogs = DialogModes.NO;  
	var check = true;  
	var page = 1;  
	// define pdfopenoptions;  
	var pdfOpenOpts = new PDFOpenOptions;  
	pdfOpenOpts.antiAlias = true;  
	pdfOpenOpts.bitsPerChannel = BitsPerChannelType.EIGHT;  
	pdfOpenOpts.cropPage = CropToType.MEDIABOX;  
	pdfOpenOpts.mode = OpenDocumentMode.RGB;  
	pdfOpenOpts.resolution = 300;  
	pdfOpenOpts.suppressWarnings = true;  
	pdfOpenOpts.usePageNumber  = true;  
	app.togglePalettes();											// toggle off palettes so Photoshop will not need to update them
	while (check == true) {  
		try {  
			pdfOpenOpts.page = page;								// open a page at it slower the using Photoshop UI ans selection all the pages you want  
			var thePdf = app.open(theFile, pdfOpenOpts);  
			page++;  
		} 
		catch (e) { check =  false };  
	}; 

	if (documents.length >= 2) { stackpages(); }
	else {
		app.togglePalettes();										// toggle on palettes
		alert("multiple Document are not open in Photoshop");
	}
}	
///////////////////////////////////////////////////////////////////////////////
//                     stack pages function                                  //
///////////////////////////////////////////////////////////////////////////////
function stackpages() {
	var orig_ruler_units = app.preferences.rulerUnits;
	var orig_display_dialogs = app.displayDialogs;
	app.preferences.rulerUnits = Units.PIXELS;						// set the ruler units to PIXELS
	app.displayDialogs = DialogModes.NO;							// Set Dialogs off
	//newFile = theFile.name.substr(0,theFile.name.indexOf(".pdf"));	//New File name
	newFile = app.activeDocument.name.substr(0,app.activeDocument.name.lastIndexOf("-"));	//New File name
	var doc = app.documents.add(app.activeDocument.width.value, app.activeDocument.height.value, app.activeDocument.resolution, newFile, NewDocumentMode.RGB, DocumentFill.TRANSPARENT ); // create a new document
	//for (var i=0;i<documents.length-1;i++) {						// stack a layer for the open document into the new document page 1 on botton	
	for (var i=documents.length-2;i>-1;i--) {						// stack a layer for the open document into the new document page 1 on top
		app.activeDocument = documents[i];							// switch active document
		var layerName = app.activeDocument.name;					// get document name
		app.activeDocument.flatten();								// Flatten remove transparency
		var idDplc = charIDToTypeID( "Dplc" );
		var desc259 = new ActionDescriptor();
		var idnull = charIDToTypeID( "null" );
        var ref24 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref24.putEnumerated( idLyr, idOrdn, idTrgt );
		desc259.putReference( idnull, ref24 );
		var idT = charIDToTypeID( "T   " );
        var ref25 = new ActionReference();
        var idDcmn = charIDToTypeID( "Dcmn" );
        ref25.putName( idDcmn, documents[documents.length-1].name );
		desc259.putReference( idT, ref25 );
		var idNm = charIDToTypeID( "Nm  " );
		desc259.putString( idNm, layerName );
		var idVrsn = charIDToTypeID( "Vrsn" );
		desc259.putInteger( idVrsn, 5 );
		executeAction( idDplc, desc259, DialogModes.NO );			// Copy Layer to document
		app.activeDocument = documents[documents.length-1];			// switch to newly created document
		layerName = layerName.substr(0,layerName.indexOf(".pdf")); 
		app.activeDocument.activeLayer.name=layerName;				// label layer with Document name
	}
	app.activeDocument = documents[documents.length-1];				// switch to newly created document
	var layers = activeDocument.layers;								// get layers
	activeDocument.activeLayer = layers[layers.length-1]			// Target Bottom Layer
	activeDocument.activeLayer.remove();							// Remove original layer
	while  (documents.length>1) {									// close all opened document except the newly created document							
		app.activeDocument = documents[0];		
		activeDocument.close(SaveOptions.DONOTSAVECHANGES);
	}
	app.togglePalettes();											// toggle user's palettes back on	
	app.runMenuItem(charIDToTypeID(("FtOn")));						// fit the document to the screen 
	app.displayDialogs = orig_display_dialogs;						// Reset display dialogs 
	app.preferences.rulerUnits = orig_ruler_units;					// reset units to original settings
}
///////////////////////////////////////////////////////////////////////////////
//                stack open pages function                                  //
///////////////////////////////////////////////////////////////////////////////
function stackopenpages() {
	var orig_ruler_units = app.preferences.rulerUnits;
	var orig_display_dialogs = app.displayDialogs;
	app.preferences.rulerUnits = Units.PIXELS;						// set the ruler units to PIXELS
	app.displayDialogs = DialogModes.NO;							// Set Dialogs off
	//newFile = theFile.name.substr(0,theFile.name.indexOf(".pdf"));	//New File name
	newFile = app.activeDocument.name.substr(0,app.activeDocument.name.lastIndexOf("-"));	//New File name
	var doc = app.documents.add(app.activeDocument.width.value, app.activeDocument.height.value, app.activeDocument.resolution, newFile, NewDocumentMode.RGB, DocumentFill.TRANSPARENT ); // create a new document
	for (var i=0;i<documents.length-1;i++) {						// stack a layer for the open document into the new document page 1 on botton	
	//for (var i=documents.length-2;i>-1;i--) {						// stack a layer for the open document into the new document page 1 on top
		app.activeDocument = documents[i];							// switch active document
		var layerName = app.activeDocument.name;					// get document name
		app.activeDocument.flatten();								// Flatten remove transparency
		var idDplc = charIDToTypeID( "Dplc" );
		var desc259 = new ActionDescriptor();
		var idnull = charIDToTypeID( "null" );
        var ref24 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref24.putEnumerated( idLyr, idOrdn, idTrgt );
		desc259.putReference( idnull, ref24 );
		var idT = charIDToTypeID( "T   " );
        var ref25 = new ActionReference();
        var idDcmn = charIDToTypeID( "Dcmn" );
        ref25.putName( idDcmn, documents[documents.length-1].name );
		desc259.putReference( idT, ref25 );
		var idNm = charIDToTypeID( "Nm  " );
		desc259.putString( idNm, layerName );
		var idVrsn = charIDToTypeID( "Vrsn" );
		desc259.putInteger( idVrsn, 5 );
		executeAction( idDplc, desc259, DialogModes.NO );			// Copy Layer to document
		app.activeDocument = documents[documents.length-1];			// switch to newly created document
		layerName = layerName.substr(0,layerName.indexOf(".pdf")); 
		app.activeDocument.activeLayer.name=layerName;				// label layer with Document name
	}
	app.activeDocument = documents[documents.length-1];				// switch to newly created document
	var layers = activeDocument.layers;								// get layers
	activeDocument.activeLayer = layers[layers.length-1]			// Target Bottom Layer
	activeDocument.activeLayer.remove();							// Remove original layer
	while  (documents.length>1) {									// close all opened document except the newly created document							
		app.activeDocument = documents[0];		
		activeDocument.close(SaveOptions.DONOTSAVECHANGES);
	}
	app.togglePalettes();											// toggle user's palettes back on	
	app.runMenuItem(charIDToTypeID(("FtOn")));						// fit the document to the screen 
	app.displayDialogs = orig_display_dialogs;						// Reset display dialogs 
	app.preferences.rulerUnits = orig_ruler_units;					// reset units to original settings
}

 

JJMack

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

I didn't try your script, but try it with result.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
Community Expert ,
Sep 03, 2021 Sep 03, 2021

Copy link to clipboard

Copied

The result.pdf is not a multiple page Pdf. My script was created to stack a multiple page pdf pages into a single document.  So After first and only page open my script put out a message that multiple document are not open and it terminates which leaves the single page open in Photoshop.

Capture.jpg

 

If a pdf has a lot of pages it take a long long time to open and stack all of its pages. That is why I have not used the script in years. It is not good for large  PDF files that have many pages. 

 

JJMack

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

Don't really think this applies to the problem but thanks anyway

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