Flipping PDF pages in QuartzDemo application

Posted by BittenApple on Stack Overflow See other posts from Stack Overflow or by BittenApple
Published on 2010-05-23T12:50:00Z Indexed on 2010/05/23 12:50 UTC
Read the original article Hit count: 367

Filed under:
|
|

I am working on modifying the quartzdemo application so that it can show another page from a multipage pdf on tap screen event.

So far I have stripped it down to the point where it displays the PDF on any page as initial page, but I can't seem to get it figured out how to make the quartzview display anything else then the initial page.

I'm guessing that the pushViewController has something to do with this.

Anyway, here's my method that draws the initial page and in sits in QuartzImages.m file:

    -(void)drawNewPage:(CGContextRef)myContext
{ 
 CGContextTranslateCTM(myContext, 0.0, self.bounds.size.height);
 CGContextScaleCTM(myContext, 1.0, -1.0); 
 CGContextSetRGBFillColor(myContext, 255, 255, 255, 1);
 CGContextFillRect(myContext, CGRectMake(0, 0, 320, 412)); 
 CGPDFPageRef page = CGPDFDocumentGetPage(pdfFajl, pageNumber);  

 CGContextSaveGState(myContext);
 CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, self.bounds, 0, true);
 CGContextConcatCTM(myContext, pdfTransform);
 CGContextDrawPDFPage(myContext, page);
 CGContextRestoreGState(myContext);
}

This gets fired up in MainViewController.m so:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// ### DISPLAY DESIRED PAGE
 QuartzViewController *targetViewController = [self controllerAtIndexPath:indexPath];
    if ([targetViewController.quartzView isKindOfClass:[QuartzPDFView1 class]])
    {
  ((QuartzPDFView1 *)targetViewController.quartzView).pageNumber = 1;

  CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("mypdftest.pdf"), NULL, NULL); 
  ((QuartzPDFView1 *)targetViewController.quartzView).pdfFajl = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
  CFRelease(pdfURL);       
    }

 [[self navigationController] pushViewController:targetViewController animated:YES];
}

Since I'm fairly new to the iPhone development (I'm currently only on page 123 in "beginning iphone 3 development" book) these controllers confuse me as hell.

I have setup an event which gets fired up fine on screen tap. The event sits in QuartzView.m and I get a simple alert on screen tap showing that the tap was registered.

I would like to use this method to draw a new page instead of showing the alert, page number doesn't matter, I'll work on incrementing (page flipping) later, I need an example of how to call these methods (if its even possible).

These are defined in QuartzView.h and I planned on using them in the tap event method:

CGPDFDocumentRef pdfFajl; int pageNumber;

Thankful for any useful input from "the internets" :)

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk