Zoom/Pinch the pdf which is loaded in a UIWebView
Asked Answered
H

3

6

I have loaded a PDF file in a UIWebView from the resource bundle.

Now, I am not able to zoom/pinch the PDF file.

I found the below 2 relevant links, but none of the answers are marked as correct -

  1. How to zoom webView with pdf file

  2. Enable zooming/pinch on UIWebView

How to make the PDF zoomable/pinchable which has been loaded in a UIWebView from the resource bundle, Will the below solution work ?

  1. Problem with pdf while opening in UIWebView

Thanks for your help.

Hearten answered 3/7, 2013 at 10:31 Comment(3)
Have you tried any of the solutions found?Prolusion
Why not using the Quick Look framework to show pdf files?Avirulent
only yourwebView.scalesPageToFit = YES; enable zooming in webView nothing-need other extra code simply load PDF in webviwe and scalesPageToFit put yesRaybourne
C
8

In your WebView on Interface Builder add check to Scale Page To Fit and you enable a Pinch ZoomIn ZoomOut ;)

Or if you want to lad better your PDF try to Look this code:

- (void)viewDidLoad 
{
    [super viewDidLoad];

    [webView loadRequest:[NSURLRequest requestWithURL:@"http:pdfURL"]];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"yourPDFFile" ofType:@"pdf"];
    NSURL *url = [NSURL fileURLWithPath:path];
    NSURLRequest * request = [NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
    //--------------AND HERE USE SCALE PAGE TO FIT------------------//
    [webView setScalesPageToFit:YES];

}

UIWebView Hope this help you.

Cartwheel answered 3/7, 2013 at 10:48 Comment(0)
C
2

//Try like this

NSString *urlstr=@"www.example.com/yy.pdf";
web=nil;
web=[[UIWebView alloc] initWithFrame:CGRectMake(0, 98, 320, 367)];
web.delegate=self;
[self.view addSubview:web];
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlstr]]];
UIPinchGestureRecognizer *pgr = [[UIPinchGestureRecognizer alloc]
                                 initWithTarget:self action:@selector(handlePinch:)];
 pgr.delegate = self;
 [web addGestureRecognizer:pgr];

// Target Action

 - (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer
 {
  recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
recognizer.scale = 1;
  }

Before this add UIGestureRecognizerDelegate in .h. Hope it will helps you..

Cytotaxonomy answered 3/7, 2013 at 10:48 Comment(0)
V
1
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSFileManager *fileManager = [NSFileManager defaultManager];

if ([fileManager fileExistsAtPath:documentsDirectory]) 
{
    NSURL *url = [NSURL fileURLWithPath:strFileName];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView setScalesPageToFit:YES];
    [webview loadRequest:request];
}
Val answered 3/7, 2013 at 13:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.