• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: count pages in PDF on OS 10.4
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: count pages in PDF on OS 10.4


  • Subject: Re: count pages in PDF on OS 10.4
  • From: Håvard Graudo <email@hidden>
  • Date: Fri, 9 Jan 2009 11:15:58 +0100

Den 8. jan.. 2009 kl. 13.24 skrev Barry Wainwright:
Not sure how reliable it is, but this seems to work on all PDFs I have tried it on:
on open theFiles
set fileData to read (item 1 of theFiles)
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {"/Type /Pages"}}
set dataChunk to last text item of fileData
set AppleScript's text item delimiters to {"/Count "}
set pageCount to first word of last text item of dataChunk
set AppleScript's text item delimiters to oldTIDS
return pageCount
end open
Barry




Den 8. jan.. 2009 kl. 20.30 skrev Roger Howard:
[...]
rxcountpages = re.compile(r"$\s*/Type\s*/Page[/\s]", re.MULTILINE| re.DOTALL)
[...]



The above approach fails on some PDFs. There are more than one instance of "/Type\s*/Page" in some PDFs and they pick the wrong one in some PDFs, returning the wrong number of pages.


Using Python with getNumberOfPages() from CoreGraphics as Jeremy suggested seem to handle this correctly.

Håvard





_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: count pages in PDF on OS 10.4
      • From: Deivy Marck Petrescu <email@hidden>
References: 
 >count pages in PDF on OS 10.4 (From: Håvard Graudo <email@hidden>)
 >Re: count pages in PDF on OS 10.4 (From: Barry Wainwright <email@hidden>)

  • Prev by Date: Iterating over items in a record, possible?
  • Next by Date: Re: Iterating over items in a record, possible?
  • Previous by thread: Re: count pages in PDF on OS 10.4
  • Next by thread: Re: count pages in PDF on OS 10.4
  • Index(es):
    • Date
    • Thread