801

Getting wrong PDF page on 64-bit iOS device only

Question:

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?

Answer1:

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

Recommend

  • Configuration profile installation on iPhone Programatically
  • Why does audio work in the simulator but not on my iPad?
  • NSBundle finds mp3 file but not m4a when trying to instantiate AVAudioPlayer
  • Set multiple TextBoxes editable after button click on WinForm
  • AVAudioPlayer doesn't load sound
  • How to implement AVAudioPlayer Inside Singleton Method?
  • Unable to add the file iOS application bundle
  • windowScriptObject method not found on Objective-C code
  • Subviews for custom UIView with Nib (.xib) don't load?
  • IDX10503: Signature validation failed
  • How to display the images in listview
  • multidatatrigger with multibinding in ControlTemplate.Triggers
  • Get the number 18437736874454810627
  • Is there a way to dynamically embed PDF Files in a JSP pulled from the file system?
  • Creating PDF from TIFF image using iText
  • Connect .sks to skscene.h
  • print() is showing quotation marks in results
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • Android fill_parent issue
  • Get object from AWS S3 as a stream
  • Circular dependency while pushing http interceptor
  • Comma separated Values
  • Linker errors when using intrinsic function via function pointer
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • AngularJs get employee from factory
  • Error creating VM instance in Google Compute Engine
  • How to set the response of a form post action to a iframe source?
  • Hits per day in Google Big Query
  • how does django model after text[] in postgresql [duplicate]
  • Java static initializers and reflection
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • Change div Background jquery
  • LevelDB C iterator
  • Bitwise OR returns boolean when one of operands is nil
  • Is there any way to bind data to data.frame by some index?
  • Django query for large number of relationships
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can i traverse a binary tree from right to left in java?
  • How can I use `wmic` in a Windows PE script?
  • How to push additional view controllers onto NavigationController but keep the TabBar?