不确定这是否是您问题的理想解决方案。
先获取PDF的宽高==>
float width = CGPDFPageGetBoxRect(PageRef, kCGPDFMediaBox).size.width;
float height = CGPDFPageGetBoxRect(PageRef, kCGPDFMediaBox).size.height;
其中 Pageref 是 PDF 页面参考。
CGSize pdfSize = CGSizeMake(width, height);
//Create one superView to webview
UIView *supView = [[UIView alloc] initWithFrame:[self.view bounds]];
supView.backgroundColor=[UIColor colorWithRed:0.663 green:0.855 blue:0.341 alpha:1]
//然后是webview
UIWebView *theWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, pdfSize.width, pdfSize.height)]];
[theWebView setContentMode:UIViewContentModeScaleAspectFit];
[theWebView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
[theWebView setScalesPageToFit:YES];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];
NSURL *filePathURL = [NSURL fileURLWithPath:filePath];
[theWebView loadRequest:[NSURLRequest requestWithURL:filePathURL]];
[supView addSubview: theWebView];
[self.view addSubview: supView];
编辑:
获取 Pageref(部分),
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];
NSURL *filePathURL = [NSURL fileURLWithPath:filePath];
CFURLRef pdfURL = (__bridge CFURLRef)[[NSURL alloc] initFileURLWithPath:filePath];
//file ref
CGPDFDocumentRef pdfDocRef = CGPDFDocumentCreateWithURL((CFURLRef) pdfURL);
CGPDFPageRef PageRef = CGPDFDocumentGetPage(pdfDocRef, 1);
float width = CGPDFPageGetBoxRect(page1, kCGPDFMediaBox).size.width;
float height = CGPDFPageGetBoxRect(page1, kCGPDFMediaBox).size.height;
NSLog(@"%f %f",height,width);