Zoom / Pinch pdf which is uploaded to UIWebView

I uploaded the PDF file to UIWebView from the resource pack.

Now I can not enlarge / pinch the PDF file.

I found the following 2 relevant links, but none of the answers are flagged as correct -

How to make a PDF with the ability to scale / pinch that was loaded into the UIWebView from the resource pack. Will the solution below work?

Thank you for your help.

+6
source share
3 answers

In your WebView on the Interface Builder, add a check on the Zoom page to match and you activate Zoom Zoom Zoom);

Or, if you want to improve your PDF file, check out 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 helps you.

+7
source

// try 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 that, add the UIGestureRecognizerDelegate to .h. Hope this helps you.

+3
source
 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]; } 
+1
source

Source: https://habr.com/ru/post/948616/


All Articles