0

是否可以用一页创建 pdf,其中包含源 pdf 中的其他 pdf 页面。我喜欢使用带有指定 CGRect 的 CGContextDrawPDFPage - 比如 UUImage 的 drawInRect 方法。

4

1 回答 1

0
 CGPDFDocumentRef PDFfile;
CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("iPhoneAppProgrammingGuide.pdf"), NULL, NULL);
        PDFfile = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
        CFRelease(pdfURL);


-(void)drawRect:(CGRect)rect
{
    {
      totalpagenumpers=CGPDFDocumentGetNumberOfPages(PDFfile);
    navBar.title = [NSString stringWithFormat:@"(%d/%d)",currentpage,totalpagenumpers];
    CGPDFPageRef page = CGPDFDocumentGetPage(PDFfile,currentpage);
    context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);
    CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
    CGContextFillRect(context,self.bounds);   
    CGContextTranslateCTM(context, -1.0, [self bounds].size.height);
    CGContextScaleCTM(context, 1.0, -1.0);
    CGContextConcatCTM(context, CGPDFPageGetDrawingTransform(page,  kCGPDFArtBox, [self bounds], 0, true));
    CGContextDrawPDFPage(context, page);    
    CGContextRestoreGState(context);
    CGAffineTransform transform = aspectFit(CGPDFPageGetBoxRect(page, kCGPDFMediaBox),
                                                CGContextGetClipBoundingBox(context));
             CGContextConcatCTM(context, transform);
         UIGraphicsBeginImageContext(CGSizeMake(self.bounds.size.width, self.bounds.size.height));

    }  



}




-(void)Next
{
       size_t pageCount = CGPDFDocumentGetNumberOfPages(PDFfile);
    if (currentpage == pageCount)
    {
       NSLog(@"aaaaa");
    }
    else 
    {


        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self cache:YES];
        [UIView commitAnimations];

        currentpage++;

        [self setNeedsDisplay];
    }

}

-(void)Previous
{

    if (currentpage == 1||currentpage<1)
    {
        {
            NSLog(@"11111");

        }

    }
    else 
    {        

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self cache:YES];
       // self.modalTransitionStyle = UIModalTransitionStylePartialCurl;

        [UIView commitAnimations];
        currentpage--;
        [self setNeedsDisplay];
    }
}
于 2012-09-13T13:22:07.647 回答