Yama
Yama

Reputation: 2649

How to find the total number of pages in pdf file loaded in objective c?

Is there any way to determine the total number of pages once the pdf file is loaded in the ipad? I am using CATiledLayer Method for loading the pdf file.

Thanking you.

Upvotes: 3

Views: 5125

Answers (2)

Yama
Yama

Reputation: 2649

Okay Thanks Altealice.I implemented in this manner and i am able to find the number of pages.

Using the following code:

NSString *pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@"mypdf" ofType:@"pdf"];    
NSURL *pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc];   
CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl); 
size_t pageCount = CGPDFDocumentGetNumberOfPages(document);

Upvotes: 4

Altealice
Altealice

Reputation: 3572

Call the function size_t CGPDFDocumentGetNumberOfPages(CGPDFDocumentRef document);

See the CGPDFDocument documentation for other useful stuff you will probably need.

         CFURLRef url = CFURLCreateWithFileSystemPath (NULL, (__bridge CFStringRef)[NSString stringWithFormat:@"%s",filePath], kCFURLPOSIXPathStyle, 0);
        CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL(url);
        CGPDFPageRef myPageRef = CGPDFDocumentGetPage(pdf, 1);
        int  totalPages= CGPDFDocumentGetNumberOfPages(pdf);

Upvotes: 8

Related Questions