我需要将 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/