Getting PDF page count using Bridge.
Posted: 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 allalert (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;
};
Code: Select allalert (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;
};