简体   繁体   中英

Getting wrong PDF page on 64-bit iOS device only

I have an iOS app that only has a problem on 64 devices. The function where the problem is, is here:

- (NSMutableData *)getPage:(NSInteger)pageNumber
{
    NSLog(@"%ld",(long)pageNumber);

    CGPDFDocumentRef SourcePDFDocument = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"full" ofType:@"pdf"]]); // Create the CGPDFDocument from the URL
    if (SourcePDFDocument == NULL) {
        return nil;
    }

    // Reference to Page current Page
    CGPDFPageRef SourcePDFPage = CGPDFDocumentGetPage(SourcePDFDocument, pageNumber);

    CGRect mediaBox = CGPDFPageGetBoxRect(SourcePDFPage, kCGPDFMediaBox);
    NSMutableData *outputData = [NSMutableData data];
    CGDataConsumerRef consumer = CGDataConsumerCreateWithCFData((__bridge CFMutableDataRef)outputData);
    CGContextRef context = CGPDFContextCreate(consumer, &mediaBox, NULL);
    // draw
    CGContextBeginPage(context, &mediaBox);
    CGContextDrawPDFPage(context, SourcePDFPage);
    CGContextEndPage(context);
    // cleanup
    CGDataConsumerRelease(consumer);
    CGContextRelease(context);

    return outputData;
}

What it does is grab a single paged from a larger pdf and convert it to NSMutableData so that it can be emailed. The problem that it is having on 64-bit devices is that it is grabbing the wrong page (18 pages before). Can anyone see the problem?

Add an explicit cast to size_t - if you leave that to be implicit there is a difference between 32 and 64 bit

// Reference to Page current Page
CGPDFPageRef SourcePDFPage = CGPDFDocumentGetPage(SourcePDFDocument, (size_t)pageNumber);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM