It is currently Sat May 25, 2013 6:20 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Count pages of a PDF document
PostPosted: Tue Apr 12, 2011 9:13 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 814
Location: Germany
The MacOS X API contains a ton of functions to view, examine, modify and generate PDF documents. If you are interested just take a look into Apple's Quartz 2D Reference Collection. For demonstration purposes I present this short code example which simply counts the pages of a PDF document:
Code:
ImportC ""
  CFRelease(CFTypeRef.L)
  CFStringCreateWithCString(CFAllocatorRef.L, CString, CFStringEncoding.L)
  CFURLCreateWithFileSystemPath(CFAllocatorRef.L, FilePath.L, PathStyle.L, IsDirectory.L)
  CGPDFDocumentCreateWithURL(CFURLRef.L)
  CGPDFDocumentGetNumberOfPages(PDFDocumentRef.L)
  CGPDFDocumentRelease(PDFDocumentRef.L)
EndImport

#kCFAllocatorDefault = 0
#kCFURLPOSIXPathStyle = 0
#kCFStringEncodingMacRoman = 0

Procedure.L OpenPDFDocument(PathAndPDFName.S)
  CFFilePath = CFStringCreateWithCString(#kCFAllocatorDefault, @PathAndPDFName, #kCFStringEncodingMacRoman)

  If CFFilePath
    CFURL = CFURLCreateWithFileSystemPath(#kCFAllocatorDefault, CFFilePath, #kCFURLPOSIXPathStyle, #False)
   
    If CFURL
      CFRelease(CFFilePath)
      PDFDocumentRef = CGPDFDocumentCreateWithURL(CFURL)
      CFRelease(CFURL)
      ProcedureReturn PDFDocumentRef
    EndIf
  EndIf

  ProcedureReturn 0
EndProcedure

Define Info.S
Define PathAndPDFName.S = "/Developer/About Xcode.pdf"

PDFDocumentRef = OpenPDFDocument(PathAndPDFName)

If PDFDocumentRef
  Info = "The PDF document '"
  Info + GetFilePart(PathAndPDFName)
  Info + "' contains " + Str(CGPDFDocumentGetNumberOfPages(PDFDocumentRef))
  Info + " pages."
  MessageRequester("PDF-Info", Info)

  CGPDFDocumentRelease(PDFDocumentRef)
EndIf


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye