开发者

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

开发者 https://www.devze.com 2023-02-05 05:05 出处:网络
Is there any way to determine the total number of pa开发者_开发问答ges once the pdf file is loaded in the ipad? I am using CATiledLayer Method for loading the pdf file.

Is there any way to determine the total number of pa开发者_开发问答ges once the pdf file is loaded in the ipad? I am using CATiledLayer Method for loading the pdf file.

Thanking you.


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);


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消