iphone - 将 CGPDFPageRef 转换为整数

标签 iphone objective-c ios xcode ipad

我需要将 CGPDFPageRef var 转换为整数,我创建了一个 if 语句来检查 PDF 页面是否小于或大于文件未显示的页面它。

- (id) setUpPDF: (int) pageNumber {    

//** = I need some integer that automatically detects PDF pages
    if ((pageNumber < **) || (pageNumber > **)) return nil;


 CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(),


                                              CFSTR("test"),
                                              CFSTR("pdf"), NULL);


    myDocumentRef = CGPDFDocumentCreateWithURL(pdfURL);
    myPageRef = CGPDFDocumentGetPage(myDocumentRef, pageNumber);

最佳答案

您可以使用CGPDFDocumentGetNumberOfPages(myDocumentRef)获取总页数。

CGPDFDocumentGetNumberOfPages() 返回一个 size_t,它是无符号整数。您可以直接将其与整数类型进行比较。

因此,对于上面的代码片段,我假设您想要类似的内容:

CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("test"), CFSTR("pdf"), NULL);
myDocumentRef = CGPDFDocumentCreateWithURL(pdfURL);
// take note that pdf page numbering starts at 1
if ((pageNumber < 1) || (pageNumber > CGPDFDocumentGetNumberOfPages(myDocumentRef))) return nil;

我建议您将参数从 (int)pageNumber 更改为 (size_t)pageNumber

关于iphone - 将 CGPDFPageRef 转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10698634/

相关文章:

iphone - 防止重新加载缓存的 iPhone Web 应用程序(滚动到顶部)

iphone - 禁用 iOS 音量按钮快门

iphone - 如何停止我不知道的NSTimer被释放

ios - 使用 xmpp 或任何其他框架在 ios 中使用 google 帐户构建聊天应用程序

ios - 推送通知不适用于 ios 8.3?

ios - 页脚 View 颜色总是比 UITableView 分隔符颜色深

php readFile() 和移动 safari

ios - mach-o 链接器错误重复符号。 header 中没有导入的 .m 文件或声明

ios - CXCallDirectoryPhoneNumber 开头不支持 0

ios - UITableView 在 UITableViewCell 内容 View 中显示 UIDatePicker