如何使用webview水平渲染pdf

时间:2011-07-12 14:29:54

标签: iphone ipad pdf uiwebview

我正在开发一个应用程序,用于在Web视图上呈现pdf,该视图在垂直方向上显示页面。有许多pdf应用程序在水平方向(滑动)上显示页面,

如何使用UIWebView水平渲染页面

此外,还有其他方式(除了webview)来呈现pdf。

TNQ

2 个答案:

答案 0 :(得分:0)

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake( 0, 0, 320, 480 )];
NSString *path = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
webView.scalesPageToFit = YES;
[self.view addSubview:webView];
[webView release];

OR

- (void) viewWillAppear: (BOOL)animated {
    [super viewWillAppear:animated];

    UIWebView *tempWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height)];  
    tempWebView.backgroundColor = [UIColor whiteColor];  
    tempWebView.scalesPageToFit = YES;
    tempWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    tempWebView.delegate = self;    
    [self.view addSubview:tempWebView]; 
    [self setWebView:tempWebView];
    [tempWebView release];  

    NSString *fileName = [pdfFile objectForKey:FILENAME_KEY];
    NSString *urlAddress = [[NSBundle mainBundle] pathForResource:fileName ofType:@"pdf"];  
    NSURL *url = [NSURL fileURLWithPath:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    [webView loadRequest:requestObj];       
}

答案 1 :(得分:0)

您的意思是PDF实际上是水平创建的吗?为什么不旋转webview?

webView.transform = CGAffineTransformMakeRotation((90*3.14159265) / 180);

webView.transform = CGAffineTransformMakeRotation((3.14159265) / 180);