photoshop script snippets - note full scripts go in the photoshop scripts forum
Moderator: PS-Moderators
by Paul MR » Wed Jul 08, 2009 8:42 pm
It seems that Bridge will cache the page count of PDF's, to get this to work, it makes the current window the files path then reads the cache pagecount.
- Code: Select all
alert (getPDFCount("~/desktop/PSGUIDE.pdf"));
function getPDFCount(filePath) {
if (!BridgeTalk.isRunning( "bridge" ) ) BridgeTalk.launch("bridge");
var filePath=File(filePath);
var data;
if ( BridgeTalk.isRunning( "bridge" ) ) {
var bt = new BridgeTalk();
bt.target = "bridge";
bt.body = 'function a(){app.document.setPresentationMode("browser","' +filePath.path+'");tn = new Thumbnail( File("'+filePath+'") ); return tn.core.itemContent.pageCount}a();';
bt.onResult = function( inBT ) { data = eval(inBT.body) }
bt.onError = function( inBT ) { data = ''; }
bt.send();
bt.pump();
$.sleep( 100 );
var timeOutAt = ( new Date() ).getTime() + 5000;
var currentTime = ( new Date() ).getTime();
while ( ( currentTime < timeOutAt ) && ( undefined == data ) ) {
bt.pump();
$.sleep( 100 );
currentTime = ( new Date() ).getTime();
}
}
if ( undefined == data ) {
data = '';
}
return data;
};
-
Paul MR
-
- Posts: 1472
- Joined: Wed Oct 18, 2006 2:44 pm
- Location: Bradford,UK
by duke2 » Mon Jul 02, 2012 7:00 am
I noticed this wasn't picking up changes in the document (whereby the page count changed). Obviously this is down to the caching. This altered version refreshes the pdf before reporting the page count.
- Code: Select all
alert (getPDFCount("~/desktop/PSGUIDE.pdf"));
function getPDFCount(filePath) {
if (!BridgeTalk.isRunning( "bridge" ) ) BridgeTalk.launch("bridge");
var filePath=File(filePath);
var data;
if ( BridgeTalk.isRunning( "bridge" ) ) {
var bt = new BridgeTalk();
bt.target = "bridge";
bt.body = 'function a(){app.document.setPresentationMode("browser","' +filePath.path+'");tn = new Thumbnail( File("'+filePath+'") ); tn.refresh(); return tn.core.itemContent.pageCount}a();';
bt.onResult = function( inBT ) { data = eval(inBT.body) }
bt.onError = function( inBT ) { data = ''; }
bt.send();
bt.pump();
$.sleep( 100 );
var timeOutAt = ( new Date() ).getTime() + 5000;
var currentTime = ( new Date() ).getTime();
while ( ( currentTime < timeOutAt ) && ( undefined == data ) ) {
bt.pump();
$.sleep( 100 );
currentTime = ( new Date() ).getTime();
}
}
if ( undefined == data ) {
data = '';
}
return data;
};
-
duke2
-
- Posts: 1
- Joined: Mon Jul 02, 2012 3:01 am
Return to Photoshop Scripting: Code Snippets
Who is online
Users browsing this forum: No registered users and 1 guest