page count in PDF files
    Ken Ray 
    kray at sonsothunder.com
       
    Mon Apr 18 17:56:38 EDT 2005
    
    
  
On 4/18/05 3:17 PM, "Robert Brenstein" <rjb at robelko.com> wrote:
> Does anyone knows or has a code snippet that would allow me to pick
> up the number of pages in a pdf file? I have inspected files from
> different versions of acrobat and there does not seem to be simple
> way to extract it programmatically. But admittedly I haven't seen pdf
> specs for quite a while.
Here you go:
on mouseUp
  answer file "Select a PDF:"
  if it <> "" then
    answer "The number of pages in the selected PDF is:" &&
stsGetNumPDFPages(it)
  end if
end mouseUp
function stsGetNumPDFPages pFile
  put url("file:" & pFile) into tData
  put word 1 to -1 of line 1 of tData into tPDFVersion
  put lineOffset("/Type /Catalog",tData) into tLine
  switch tPDFVersion
  case "%PDF-1.2"
    put line (tLine-1) of tData into tPageMarker
    break
  default
    put line (tLine+1) of tData into tPageMarker
    break
  end switch
  put word 2 of tPageMarker into tObjectNode
  put lineOffset(tObjectNode && "0 obj",tData) into tObjStart
  put lineOffset(">>",tData,tObjStart) + tObjStart into tObjEnd
  put line tObjStart to tObjEnd of tData into tObjBlock
  filter tObjBlock with ("/Count*")
  return (word 2 of tObjBlock)
end stsGetNumPDFPages
HTH,
Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com
    
    
More information about the use-livecode
mailing list