Copy link to clipboard
Copied
Hello, there.
I'm scripting for PS and am getting some problems because some of the PDF files I need to process are being opened as images (no dialog asking PDF details). Now I'm trying to figure it out and am opening manually. I have two PDF files. One of them Photoshop opens as expected (showing the dialog). The other one, which is giving me problems in script, opens directly.
Any suggestion?
Copy link to clipboard
Copied
Try using Action manager code and show the dialog the DOM does not show the dialog. The Dialog most likely would not show if the PDF file is a Photoshop PDF. If the PDF is an Acrobat PDF I would think the Import PDF Dialog would open.
Copy link to clipboard
Copied
Thanks!
But how the PDFs could be different since them both are exported from the same InDesign file, using absolutelly same settings?
Copy link to clipboard
Copied
If I force the dialog with All app.open(file) does not seen to process the file passed instead it open a file select dialog and I have to select the PDF a second time and when I do I get the Import PDF dialog for the PDF I select.
var theFile = File.openDialog("Select your PDF file", "Select:*.pdf");
app.displayDialogs = DialogModes.ALL;
alert(theFile)
app.open(theFile);
Copy link to clipboard
Copied
What is your code to open them? Do you have code to make sure all dialogs open?
Copy link to clipboard
Copied
Thanks, Chuck. No, I don't, since I don't want any dialog in my script.
But I'm getting wrong positions in my final file because these particular ones (and I don't know why) are opening like simple JPGs and not as PDFs, as I expect (with all the background in its original size).
Copy link to clipboard
Copied
This file, for example: https://drive.google.com/file/d/1ktQlINykh9B72kf9LBANHOBlpuS2SEyF/view?usp=sharing
If I open it using Acrobat, it shows me the entire page size.
If I open it in Photoshop, the dialog won't show, and the image is opened cropped.
Of course this is not what I expect. A lot of other images (in the same InDesign document) behaves as I expect when I manually open them in Photoshop.
Copy link to clipboard
Copied
If it a Acrobat PDF I would think the first page only would open as a document. At one time I wrote a Script to open an Actobat PFF and stack all the PDF pages in a document. OpenPDFpages.jsx
/* ==========================================================
// 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
}
Copy link to clipboard
Copied
In addition to the code from JJMack, you may also find parts of Paul Riggott's PDF Processor II script helpful:
https://raw.githubusercontent.com/Paul-Riggott/PS-Scripts/master/PDF%20ProcessorII.jsx