Copy link to clipboard
Copied
Hi,
I want to save an imported/opened PDF as PNG graphic – in the same folder as the PDF (not as a batch event and with PDF files from different folders).
But after opening the PDF file Photoshop creates a "temporary file" without file path.
Is it possible to get the file path of the PDF?
"Hint": Opening a PDF file and listening via ScriptListener.8li I get this line in ScriptingListenerVB.log:
Call desc9.PutPath( idnull, "D:\\folder\\subfolder\\file.pdf" )
thanks!
carlos
Copy link to clipboard
Copied
Moving to Photoshop Scripting
Copy link to clipboard
Copied
EDIT ! :
Also if you want to be sure, you're getting the path you want and you're working with several documents, you may use app.activeDocument.name as indicator and loop through recentFiles list:
var Path, NameTemp, Name, temp;
try {
Path = app.activeDocument.path;
} catch (e) {
Path = 0;
//decode and clean input
//Then delete numerical ending of multi page pdfs
NameTemp = decodeURI(app.activeDocument.name.toString().
replace(/((-\d\d)\.pdf)|((-\d)\.pdf)/g), '');
//if it was a single page pdf
NameTemp = NameTemp.replace('.pdf', '');
//if undefined was appended (yes, it may happen with regex)
NameTemp = NameTemp.replace('undefined', '')
Name = NameTemp;
for( var i =0; i < app.recentFiles.length; i++){
temp = decodeURI(app.recentFiles.toString()).split('/');
temp = temp[temp.length-1].replace('.pdf', '');
if ( temp == Name){
Path = decodeURI(app.recentFiles.toString());
break;
}
}
}
if(!Path){
alert ("Script couldn't find the path of opened file");
} else {
alert (Path);
}
Copy link to clipboard
Copied
I hope it will be helpful. You can access list of paths of opened files via recent files list, for example:
var Path, temp;
try {
Path = app.activeDocument.path;
} catch (e) {
Path = app.recentFiles[0].toString();
}
The most recent file is the one, you were looking path for.
If there is more than one open pdf, you may add to the index of app.recentFiles a number representing index of app.documents.
There is also another way to access path of opened files. If you're using Script listener, you may parse .log on your desktop using regex - search for: desc53.putPath( idnull, new File( ... . But remember to escape the string, otherwise it won't work. Also, if your log is too long, it will loop for quite some time...
Please, correct if I'm wrong. I'm using the solution with recentFiles[ ] to bypass Save As dialog box and it's working. It was tested on CS6 and CS5, as these versions are used in my office.