How can I get a total page count of a PDF before placing every page in the PDF?

Before the [long] spiel, I'm using javascript in InDesign CS3.
I'd like to create a script that places a multiPage PDF in any number of different impositions. (saddle stitch, 4up signatures, 16up signatures etc.)
I've easily created a script that iterates through a PDF and places it into a new document as (4,1|2,3), (8,5|6,7) etc, which works for printing in duplex, folding each page in half, and gluing the resulting spines to make a simple thick book (for PDFs with more than, say, 64 pages).
However, the next step is to re-write the script to create a saddle stitch document (16,1|2,15), (14,3|4,13) ... (10,7|8,9). For this I need to know how many pages there are in the PDF before I start placing the PDF pages, and then making the new document [int((PDFpages+3)/4)] pages long.
Is there a simple way to get the count of PDFpages without going through a loop and placing the next page from the PDF until the placed page number equals the first page number?
This way seems wasteful:
var totPDFPages = 1;
app.pdfPlacePreferences.pageNumber = totPDFPages;
myPDFPage = sheetFront.place(File(srcPDF), [0,0])[0];
var pdfFirstPage = myPDFPage.pdfAttributes.pageNumber;
while (doneCounting == false) {
totPDFPages += 1;app.pdfPlacePreferences.pageNumber = totPDFPages;
myPDFPage = sheetFront.place(File(srcPDF), [0,0])[0];
if (myPDFPage.pdfAttributes.pageNumber == pdfFirstPage) {
totPDFPages -=1;
doneCounting = true;
alert("PDF has " + totPDFPages + " pages!");exit();
myPDFPage.remove();
NB. Javascript above *hasn't* been run, but should look similar once debugged.
The only thing I've though of to relieve the sheer duplication of placing the PDF twice (once for the count, and once for the imposition), is to create an array of impoPages[counter]=myPDFPage, and then shuffle the pages referenced by the array to the correct sheet and position.
It'd be much easier to be able to assign pageCount = File(srcPDF).pageCount !!!
Thanks for any help/tips or even a simple "What are you smoking, man!?"
Cheers,
Jezz

this will get almost all pdf pages count.
jxswm
function getPDFPageCount(f){
  if(f.alias){f = f.resolve();}
  if(f == null){return -1;}
  if(f.hidden){f.hidden = false;}
  if(f.readonly){f.readonly = false;}
  f = new File(f.fsName);
  f.encoding = "Binary";
  if(!f.open("r","TEXT","R*ch")){return -1;}
  f.seek(0, 0); var str = f.read(); f.close();
  if(!str){return -1;}
  //f = new File(Folder.temp+"/123.TXT");
  //writeFile(f, str.toSource()); f.execute();
  var ix, _ix, lim, ps;
  ix = str.indexOf("/N ");
  if(ix == -1){
    var src = str.toSource();
    _ix = src.indexOf("<< /Type /Pages /Kids [");
    if(_ix == -1){
      ps = src.match(/<<\/Count (\d+)\/Type\/Pages\/Kids\[/);
      if(ps == null){
        ps = src.match(/obj <<\\n\/Type \/Pages\\n\/Count (\d+)\\n\/Kids \[/);
        if(ps == null){
          ps = src.match(/obj\\n<<\\n\/Type \/Pages\\n\/Kids \[.+\]\\n\/Count (\d+)\\n\//);
          if(ps == null){return -1;}
          lim = parseInt(ps[1]);
          if(isNaN(lim)){return -1;}
          return lim;
        lim = parseInt(ps[1]);
        if(isNaN(lim)){return -1;}
        return lim;
      lim = parseInt(ps[1]);
      if(isNaN(lim)){return -1;}
      return lim;
    ix = src.indexOf("] /Count ", _ix);
    if(ix == -1){return -1;}
    _ix = src.indexOf(">>", ix);
    if(_ix == -1){return -1;}
    lim = parseInt(src.substring(ix+9, _ix));
    if(isNaN(lim)){return -1;}
    return lim;
  _ix = str.indexOf("/T", ix);
  if(_ix == -1){
    ps = str.match(/<<\/Count (\d+)\/Type\/Pages\/Kids\[/);
    if(ps == null){return -1;}
    lim = parseInt(ps[1]);
    if(isNaN(lim)){return -1;}
    return lim;
  lim = parseInt(str.substring(ix+3, _ix));
  if(isNaN(lim)){return -1;}
  return lim;

Similar Messages

  • How can I get cloud totally off my ipad -

    How can I get cloud totally off my ipad - I hate the tabs it installed on Safari.  I deleted the account on Ipad but it is still there (just asking for sign in) and still tabs taking up space on an already small screen...thx! Or even how to remove the tabs!

    Apple does not support downgrading. Have you tried to reset your router?
    Or gone into the settings, general, reset, reset all network settings?

  • When I switched computers my songs now cut off and don't play out.  How can I get my songs back to play fully that I purchased from ITunes over the past years?

    When I switched computers my songs now cut off and don't play out.  How can I get my songs back to play fully that I purchased from ITunes over the past years?

    Other people have been having similar problems with songs over the last few days, I assume that there has been a problem with Apple's servers.
    Depending upon what country that you are in (music can't be re-downloaded in all countries) then try deleting those tracks from your iTunes library and redownload them via the Purchased link under Quick Links on the right-hand side of the iTunes store home page on your computer's iTunes : re-downloading.
    If you aren't in a country where you can re-download music or if they re-download in the same state then try the 'report a problem' link from your purchase history : log into your account on your computer's iTunes via Store > View My Account and you should then see a Purchase History section with a 'see all' link to the right of it ; click on that and you should see a list of your purchases ; find those songs and use the 'Report a Problem' link.

  • I have an ancient laptop (from 2005) that has my entire music library. This laptop barely works and some keys don't type anymore. How can I get all this music transferred to another computer, or available to me on the cloud?

    I have an ancient laptop (from 2005) that has my entire music library. This laptop barely works and some keys don't type anymore. How can I get all this music transferred to another computer, or available to me on the cloud?

    No... do not move programs.
    About the iTunes library files
    Your iTunes library files track the media you add to iTunes, how you've organized it, and other information such as playlists. By default, these two files are in your iTunes folder:
    Mac OS X: /Users/username/Music/iTunes/
    Windows XP: C:\Documents and Settings\username\My Documents\My Music\iTunes\
    Windows Vista: C:\Users\username\Music\iTunes\
    Windows 7: C:\Users\username\My Music\iTunes\
    Windows 8: C:\Users\username\My Music\iTunes\

  • I bought and downloaded some music off of the internet on my laptop that uses Windows 8. How can I get my music to open automatically in my itunes instead of opening in the music app?

    I bought and downloaded some music off of the internet on my laptop that uses Windows 8. How can I get my music to open automatically in my itunes instead of opening in the music app (the orange sqaure with headphones)? Currently I have had to often downloads and sift through all my files to find the ones I want to open into itunes, and it's irritating.

    Media is only where the user puts it.
    Installing iTunes does not and has never caused media to magically appear on the computer.
    Copy the ENTIRE iTunes folder from the old computer (or backup of the old computer) to the new computer.

  • How can i get my POP email pushed to my iphone5 instantly (not every 15 minutes) like my old blackberry did?

    how can i get my POP email pushed to my iphone5 instantly (not every 15 minutes) like my old blackberry did?

    You can't, RIM uses a proprietary mail server (in Canada) that pushes mail to BB devices. You will need to get an iCloud, Yahoo, Gmail Exchange, or Exchange mail account to pust mail to your iPhone.

  • Fire FTP does not work with Firesfox 4. It worked OK with version 3. How can I get a New Fire FTP? Last version of FTP does not solve the problem

    Fire FTP does not work with Firesfox 4. It worked OK with version 3. How can I get a New Fire FTP? Last version of FTP does not solve the problem

    I need to know if it's 64-bit or 32-bit.
    If it's 64-bit, try copying the mms.cfg file from C:\WINDOWS\syswow64\Macromed\Flash to C:\WINDOWS\system32\Macromed\Flash

  • HT1338 How can I get my iphone 4s to connct to my itunes? Says I need the 10.6.3 so I down loaded itunes 10.7 which tells me I need a 10.6.3 operating system and my mac is only a 10.5.8. What do I need to do?

    How can I get my iphone 4s to connct to my itunes? Says I need the 10.6.3 so I down loaded itunes 10.7 which tells me I need a 10.6.3 operating system and my mac is only a 10.5.8. What do I need to do?

    You will need to upgrade to Snow Leopard first - if your Mac can run it:
    Requirements for OS X 10.6 'Snow Leopard'
    http://support.apple.com/kb/SP575
    Whilst Apple have withdrawn Snow Leopard from their stores, you can still get it from Apple by calling 1-800-MY-APPLE (if you are in the USA) and they will supply the SL DVD for $30.  You can also purchase the code to use to download Lion from the same number.
    If you are outside the US call your national Apple Helpline:
    http://support.apple.com/kb/HE57
    If you're in the UK, use this number: 0871 508 4400
    When you have installed it, run Software Update to download and install the latest updates for Snow Leopard.

  • How can I get sleep mode back to my RAZR M since it went away with the latest upgrade?

    How can I get sleep mode back to my RAZR M since it went away with the latest upgrade?
    Thanks

        Hi aztigger!
    Good news! You can still put the screen into sleep mode under Settings > Display > Sleep. Let me know if that helps!
    Thanks,
    AdamE_VZW
    Follow us on Twitter @VZWSupport

  • My icloud emails arent arriving most of the time and a few days ago my iphone and ipad started showing "Can't Get Mail" box. This has not happened before since I set up the iclud email address with the purchase of my ipad about a month ago.

    My icloud emails arent arriving most of the time and a few days ago my iphone and ipad started showing "Can't Get Mail" box. This has not happened before since I set up the iclud email address with the purchase of my ipad about a month ago.

    That's one of the weird things.. it recognizes it maybe 10% of the time. And usually, only after I do the two-button reset. Problem is.. since it won't charge above 2%, anytime I try to do a restore or anything like that using iTunes, my device shuts off and I lose whatever progress I'd made.
    So, an update... after reading through a bunch of similar complaints (there are literally 1000's of them so there's NO WAY this isn't somehow ios7 related, thanks a lot APPLE ) I decided to try a restore in recovery mode. After 3 hours and several disconnections... I ended up having to just set it up as a new iPad, as the restore did nothing. Weirdly though... as I was doing the restore in recovery mode.. I noticed I'd gotten up to a 10% charge.. higher than it's been since September, so after setting it up as a new device, I turned it off and plugged it in using the wall charger. 2 hours later and I was up to 38%. Still not great, as my iPad, before ios7 could've fully charged twice in the amount of time it took for me to now get 28% more of a charge. And that's with a fully cleaned out device.. so that really ***** and I'm now more confused than ever.
    But I'm gonna leave it overnight charging and see what I come up with tomorrow. Sadly, when I paid $600 for it in February, I never expected to have to play "wait and see" with it...

  • How can I get my HP Officejet Pro 8100 to work. I had HP  on the phone for over two hours and thought it was fixed. Now it just will not print at all.

    How can I get my HP Officejet Pro 8100 to work.
    I'm using an  iMac (21.5-inch, Late 2013) running Yosemite. I spent hours on the phone with HP who did their best and thought they had solved the problem Now it has stopped printing completely. Just says 'idle' or' connecting to printer' but never does.

    Greetings paulr.paulr,
    Welcome to the Apple Support Communities!
    I understand that you are unable to print from your Mac running Yosemite on your HP Officejet Pro 8100. I know that printer issues can be very frustrating, but I believe the information in the attached article will be able to assist you. I would suggest reading over and systematically working your way through the suggested troubleshooting steps located in the following article. If any issues arise as you work your way through the steps, or if you work your way completely to the end and reset the printing system and the issue continues, please let me know. 
    OS X Yosemite: Printing troubleshooting
    Cheers,
    Joe

  • I bought a new apple computer and when i synced the iPod with computer it erased all my previous personal music.How can i get my music back to where it was before syncing with new computer?

    I bought a new apple computer, when I synced my ipod after I thought i had transferred all my music all my old music was erased.  How can I get  back my old music on my  ipod?

    You can redownload iTunes purchases by:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store

  • How can I get a drop-down list selection also be selected in another field with the same list but a different name?

    I have a street address and a billing address. A question is posed with a checkbox — "Is the billing address the same as the street address?" If Yes is checked, the street address automatically fills the billing fields. If No is checked, the user must fill in new information. In both the street address and billing addres, the State field is a drop-down list. How can I get the drop-down list selection in the street address State also be selected in drop-down list for the billing address State?

    Has anyone done this?

  • How can I get all options under edit in iPhoto to appear and revert in red, the only option it gives me is to select multiple

    how can I get all options under edit in iPhoto on my phone to appear it has revert in red on theleft side & done on the right side, the only choice it gives me is select multiple

    The usual cause of that issue is a corrupted or missing font that Firefox replaces by another, in this case a bold, font.
    As a test you can try to disable the default font and choose a few different fonts (Arial, Verdana, Tahoma, Times New Roman) to see if you can identify the culprit.<br />
    you will have to reinstall that corrupted font.

  • How can i get iTunes on my new lap top to look at my server for the music

    I have a new lap top with vista ultimate. I can't get it to "see" the music stored on the server, so my iTUnes on the lap top is blank.
    How can i get my iTunes on my new lap top to look at my server for the music?
    someone mentioned creating an alias on the server and then dragging that onto the c: drive iTunes folder?
    Can anyone help me?

    They should be in your itunes media folder. Use an external hard drive and just copy that to your new computer. I'm sure there's an easier way like this one (iTunes>File>Library>Export Library>External Hard Drive) but I never tried it before. Anyways, once that's done, just simply authorize your itunes account to play music you bought on to the new computer.

Maybe you are looking for

  • Error in Quantity Contract

    Hi Experts, I have created a quantity contract in VA41 and with that reference I am creating now a sales order. But while saving I am getting error "The Customer Requires Complete Delivery: Item XXXX has not been confirmedu201D Message number: V1293.

  • External Hard Drive isn't being found in Time Machine. Cant back up my mac.

    Just bought a samsung 500gb external hard drive because I need to backup my mac to do a full system reboot because it is completely messed up after downloading the new yosemite update. But when I go to time machine it isn't offered as an option for a

  • Two ipods in the house

    We have two ipods (a mini for me and one for my husband). When we go to itunes, how can we sync different songs to each ipod. It automatically syncs all the music to each ipod. Any thoughts? thanks.

  • What is clearing cache for?

    I have an iPad 2. What is the purpose of clearing the cache? What's it for?

  • WCF Basic Http Send Adapter Observation (BUG in WCF Adapter ?)

    Hi, I have a request response WCF Basic Http send adapter with URL say http://dds.testservice.com/service I send a request and get a response in my orchestration. Everything works fine. I have a scope around the send receive shape in orch to catch ex