是否可以使用一个页面创建pdf,其中包含来自源pdf的其他pdf页面。 我喜欢使用CGContextDrawPDFPage和指定的CGRect - 类似UUImage的drawInRect方法。
答案 0 :(得分: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];
}
}