J.Chandrasekhar Reddy
J.Chandrasekhar Reddy

Reputation: 101

displaying pdf file in UIScrollview Horizontally

In a pdf file using UIWebView, I need to scroll horizontally instead of vertically. I have created UIScrollView in the form:

UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.contentSize = CGSizeMake(2000, 420);
scrollView.bounces = NO;
scrollView.alwaysBounceHorizontal = NO;
scrollView.alwaysBounceVertical = NO;
scrollView.backgroundColor = [UIColor whiteColor];

and now adding the UIWebView in to UIScrollView as

[scrollView addSubview:webView];

it is not displaying the pdf file but if i give code like this

[self.view addSubview:webView];

now it displays the file but it vertical scroll

I need to make it to scroll horizontally please help me. Thanks in advance.

Upvotes: 4

Views: 2896

Answers (3)

Rachit Khattar
Rachit Khattar

Reputation: 138

You can straight away put the pdf on UIWebView and if it is multiple pages it will scroll automatically. You can try the code below

UIWebView *webView = [[UIWebview alloc]init];

webView.frame = "SET FRAME"

[self.view addSubView:webView];

// create a URL for the pdf file which is in you project

NSURL *pdfURL = [[NSBundle mainBundle]URLForResource:"Name of pdf" withExtension:@"pdf"];**

[webView loadRequest:[NSURLRequest requestWithURL:pdfURL]];

//just to show the scroll indicators

[webView.scrollView flashScrollIndicators];

I do it this way....

Upvotes: 0

Deepak Bharati
Deepak Bharati

Reputation: 280

After your code:

UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.contentSize = CGSizeMake(2000, 420);
scrollView.bounces = NO;
scrollView.alwaysBounceHorizontal = NO;
scrollView.alwaysBounceVertical = NO;
scrollView.backgroundColor = [UIColor whiteColor];
[scrollView addSubview:webView];

add this also:

[self.view addSubview:scrollView];

if you have not added it earlier.

Upvotes: 1

amrut1
amrut1

Reputation: 124

As per my knowledge horizontal scroll with PDF in webview is not possible.you can use below opensource projects

Leaves

Reader

Else you can use the QLPreviewController

Upvotes: 0

Related Questions