• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

determine the number of pages of a pdf before any operations on it

Community Expert ,
Apr 24, 2009 Apr 24, 2009

Copy link to clipboard

Copied

Do any of You know how to determine the number of pages of a pdf-file (selected with the openDialog for example)?

Somehow I fail to grasp how to achieve that any way short of actually opening/rasterizing all pages without prior knowledge of the actual number.

I would like to use that information to determine the number of elements for a contact-sheet-like procedure beforehand.

MultiPageImporter2.0.jsx, which is an Indesign-Script by Scott Zanelli, obviously does it, but so far I’ve failed to successfully utilize his functions.

Anyway, have a nice weekend

pfaffenbichler

TOPICS
Actions and scripting

Views

11.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Apr 27, 2009 Apr 27, 2009

Ok now this works....

Install X's script amending CSx version

Then run this script amending the pdf location and CS version... (NB: will not work with CS2. CS,CS3 and CS4 should be ok)

/////////////////////////////////////////////////////////////

var pdffile = File("~/Desktop/56 pages.pdf").fsName;

////////////////////////////////////////////////////////////

var file = new File("/Applications/Adobe Photoshop CS3/Presets/Scripts/macexec.app/contents/macexec");

var pdfcnt = File("~/pdfcnt");

if(pdfcnt.exi

...

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 29, 2009 Apr 29, 2009

Copy link to clipboard

Copied

Thanks!

Unfortunately I have failed to eliminate said pop-up yet.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 29, 2009 Apr 29, 2009

Copy link to clipboard

Copied

It could be down to the OS, I was using Leopard on the laptop. I have Tiger on the G5 so I will see what happens on there. Have to go out so it will be later on.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 29, 2009 Apr 29, 2009

Copy link to clipboard

Copied

I’m on Leopard, too, so it proabably isn’t worth Your time to search

further – just one of those things, I guess.

Anyway, thank You for Your time and effort!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 29, 2009 Apr 29, 2009

Copy link to clipboard

Copied

I wonder how you have your Terminal preferences set?

On mine under "Shell":

When the shell exits: is set to Close the window

Prompt before closing: is set to Never

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 29, 2009 Apr 29, 2009

Copy link to clipboard

Copied

You’re right, my preferences were »close if shell the exited cleanly«

and »always«; now it keeps »quiet«.

Thanks for Your patience!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 29, 2009 Apr 29, 2009

Copy link to clipboard

Copied

Glad you are working nowChristoph.

X this forum is a bit slow as its taken 24 hours for your reply to show up, must be because of the picture. Great information from you as usual!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Apr 29, 2009 Apr 29, 2009

Copy link to clipboard

Copied

X this forum is a bit slow as its taken 24 hours for your reply to show up, must be because of the picture. Great information from you as usual!

Actually, the first post came up blank. The post/edit with the pic is

from the morning (my TZ). The forum software just dropped the Edited

note that explained this.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 27, 2009 Apr 27, 2009

Copy link to clipboard

Copied

Paul, did you change the permissions on the text file to make it an executable file? This needs to be done for OSX

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 07, 2012 Jan 07, 2012

Copy link to clipboard

Copied

OK so lets do it working on WIN and MAC without any shell script.
This solution is not the best but its working.

I used Try catch to solve it.
Only issue is that you should at least somehow know how many pages you expect in pdf.. this mean if you are working with books or flyers...
Then set the maxPagesCount to that number.
I am working with pdfs with max 20pages.. so i start open the 20 then 19 then 18 and when i am success i know the amount of pages.
Its not the quicker way but its usable.

var maxPagesCount = 20;
var actPagesCount = maxPagesCount;


var opts1 = new PDFOpenOptions();
opts1.usePageNumber = true;
opts1.antiAlias = true;
opts1.bitsPerChannel = BitsPerChannelType.EIGHT;
opts1.resolution = 10; //it will load faster the test page
opts1.suppressWarnings = true;
opts1.cropPage = CropToType.MEDIABOX;

myFunction = function () {

  try {  

      app.displayDialogs = DialogModes.NO;
      var fileList = openDialog();
      for (i = 0; i < fileList.length; i++) {
        actPagesCount = maxPagesCount;
        getPagesCount(fileList,maxPagesCount);
        alert(actPagesCount);
      }

  } catch (exception) { 

    alert(exception);

  }

};

getPagesCount = function (checkFile, lastPageID) {

  try {          
 
    for (var checkPage = lastPageID; checkPage > 0; checkPage--) {
      opts1.page = checkPage;                    
      var docRef = open(checkFile, opts1, false);                  
      docRef.close(SaveOptions.DONOTSAVECHANGES);                  
      actPagesCount = lastPageID;                  
      return;                  
      checkPage=0;                              
    }

  } catch (exception) {

    // Look for next page        
    checkPage--;        
    getPagesCount(checkFile,checkPage);

  }

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 07, 2012 Jan 07, 2012

Copy link to clipboard

Copied

Yes Mike came to the same conclusion a while back, so the page count is irrelevant so long as the loop has high number.

There is an example of this here...

http://www.ps-scripts.com/bb/viewtopic.php?f=10&t=1882&sid=153338764ecc6693b89cb7c1943c75c3

There is also a way of getting the page count via Bridge..

http://www.ps-scripts.com/bb/viewtopic.php?f=13&t=2769&sid=153338764ecc6693b89cb7c1943c75c3

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2012 Jan 09, 2012

Copy link to clipboard

Copied

LATEST

Paul, drafter2, I haven’t checked out the improved solutions yet, but thanks for the heads-up.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines