How to find the total number of pages in a pdf file loaded into object c?

Is it possible to determine the total number of pages after uploading a PDF file to ipad? I am using the CATiledLayer method to load a pdf file.

Thank you.

+3
source share
2 answers

Call function size_t CGPDFDocumentGetNumberOfPages(CGPDFDocumentRef document);

See the CGPDFDocument documentation for other useful things you are likely to 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);
+6
source

Ok, thanks Altealice.I is implemented this way and I can 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);
+4
source

Source: https://habr.com/ru/post/1786316/


All Articles