Copy link to clipboard
Copied
Pdf file was opened in PS via standard dialog for opening pdf's.
Then I execute
error
So is it possible to get an original Pdf file path after it was opened?
Copy link to clipboard
Copied
andyf65867865 schrieb
… So is it possible to get an original Pdf file path after it was opened?
Sorry. But no.
----------
edit: Your title is incorrect. Not getting a filename, but getting filepath
Copy link to clipboard
Copied
If it has a backing file
alert(documents[0].path + "/" + documents[0].name);
PDF files are not opened pages, image, 3d are openeded into new documents that have not been saved there are no backing files for them. The message show this.
alert(documents[0].name);
Will sort of get the PDF name it will be sometheing like PDFName+"-Page#".PDF
I do not know if you can get its path through Photoshop javascript file system support may be able to resolve the path however there could be several pdf with the name on your system. I do not know Photoshop scripting well don't know all the information Photoshop may have about open documents if there is something like a parent document etc.
Copy link to clipboard
Copied
I have to append to my post. I just check CC 2017 seem to be able to save PDF files that are compatible with new version of Photoshop and will open into new version of Photoshop as a layered document. There are all sort of pop-up dialogs when you first save the document as a pdf. you get a warning if you use option to be compatible with Photoshop. Acrobat reader only shows the pdf file as a composite image. But if you open that type of PDF file it will open in new Photoshop versions as a layered document and you can get the full path of the backing PDF file.
Copy link to clipboard
Copied
We can get filename but could not get a file Path..
alert(documents[0].name)
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.
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);
}