iospdfnsfilemanagernewsstand-kit

objective-c, getting the number of pages of a pdf document


This might be a silly question but please help me out. I just want to know how to extract the number of pages of a PDF document saved on an issue's contentURL (Newsstand framework). In the must efficient way, because I just want number up correctly some thumbs of the pages I also have saved in the contentURL. In other words: Is it possible to know the number of pages of a pdf without open it?


Solution

  • Check this out: https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGPDFDocument/Reference/reference.html

    There is this method:

    size_t CGPDFDocumentGetNumberOfPages(CGPDFDocumentRef document)
    

    That gives you the number of pages.

    Implement it as such:

    NSURL *pdfUrl = [NSURL fileURLWithPath:yourPath];    
    CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl);