如何找到在objective c中加载的pdf文件的总页数?

时间:2023-02-09 16:01:18

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.

一旦pdf文件被加载到ipad上,是否有办法确定总页数?我正在使用CATiledLayer方法来加载pdf文件。

Thanking you.

感谢你。

2 个解决方案

#1


6  

Call the function size_t CGPDFDocumentGetNumberOfPages(CGPDFDocumentRef document);

调用函数size_t CGPDFDocumentGetNumberOfPages(CGPDFDocumentRef文档);

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

请参阅CGPDFDocument文档,了解您可能需要的其他有用内容。

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

#2


4  

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

好的谢谢Altealice。我以这种方式实现,并且我能够找到页数。

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

#1


6  

Call the function size_t CGPDFDocumentGetNumberOfPages(CGPDFDocumentRef document);

调用函数size_t CGPDFDocumentGetNumberOfPages(CGPDFDocumentRef文档);

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

请参阅CGPDFDocument文档,了解您可能需要的其他有用内容。

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

#2


4  

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

好的谢谢Altealice。我以这种方式实现,并且我能够找到页数。

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