iOS : jump to a specific slide in ppt - ios

I've one ppt file locally that I'm opening with UIWebView with below code, file having 10 slides, now with the requirement, I want to jump to a specific slide, something like if I want to directly jump to slide#3 then how to do it with this code?
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:#"ppt"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
//open ppt into UIWebView like,
[self loadDocument:#"newone" inView:self.myWebview];
I searched here, and found this, they are doing
Link to http://www.whatever.com/hello.ppt#4 for slide 4 to be opened initially.
but my ppt file is saved into document directory (locally) within my app.
Any suggestion?

You can set the offset of UIWebview ScrollView.
[[webView scrollView] setContentOffset:CGPointMake(widht, height) animated:YES];
Find height of one slide in current zoom scale. Multiply it with four as forth page to open initially. and put in above code with point CGPointMake(0, heightYouCalculated)

Related

setZoomScale breaks ability to scroll in UIWebView

One of my apps has a UIWebView which loads a particular pdf from the user's device. After the webView has loaded I would like to set the zoom scale and contentOffset. However, if the pdf takes a while to load, the user can no longer scroll - they can see the whole pdf and can zoom in/out, but it only zooms into the top-left corner and you can't scroll at all. (You can scroll if you zoom in further than zoom scale).
(For completeness) I run this code in viewDidAppear:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *path = [documentsPath stringByAppendingPathComponent:#"filename.pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
The main code:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
if (!loadFailedBool) {
[self performSelector:#selector(zoomIntoWebView) withObject:nil afterDelay:0.0];
}
}
- (void)zoomIntoWebView {
[webView.scrollView setZoomScale:5.0 animated:NO];
webView.scrollView .contentOffset = CGPointMake(600, 420);
}
I have removed any unnecessary code, but as you can see, it runs the zoom function after a delay of 0.0. In this circumstance, the above bug happens every time. If I set it to something like 0.3 the code works fine, about 90% of the time.
As a temporary fix, I have set the delay to 0.6 but it is far from ideal, especially if a user is on a older device. If this bug happens every time, this feature of the app becomes unusable. If anyone has any suggestions or a similar problem it will be great to find a solution. Knowing when the pdf has finished loading would probably fix it.

UIWebView content loading at wrong position

I am trying to add three UIWebView to my iOS app. I have successfully read the "HTML code" into the UIWebView and it displays the content fine, but one of the three views are displayed at a wrong position.
Here is the code I used to load the data:
-(void) webViewLoading {
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:#"load" ofType:#"html"];
NSString* embedHTML = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[self.choice_1_webview loadHTMLString: embedHTML baseURL: nil];
[self.choice_2_webview loadHTMLString: embedHTML baseURL: nil];
[self.choice_3_webview loadHTMLString: embedHTML baseURL: nil];
}
Here is what I got in the simulator:
and here is what I have in Xcode:
The first UIWebView does not load correctly and the grey rectangle is the background color of the UIWebView. Does anyone know what could have caused this? I created the three UIWebViews exactly the same (copied and pasted in the interface builder).
===
It looks like the content of the first UIWebView has a smaller height than the other two. It is weird however because the contents are generated from the same file.

how to generate ppt, doc thumbnail in iOS

As the title says,
I'm essentially looking for a way to generate a thumbnail from a .DOC, .DOCX, or .PPT file in iOS in background.
I know this is not exactly the type of file you want, but is a starting point:
How can I programatically generate a thumbnail of a PDF with the iPhone SDK?
http://davidbits.blogspot.com.es/2012/10/ios-getting-thumbnail-of-pdf-document.html
For opening anything (PDF, Pages, Word, Numbers, Excel, Images etc) that the Mail.app or Safari can open, you usually use the UIWebView.
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0F, 0.0F, 320.0F, 480.0F)];
NSURL *pdfURL = [NSURL URLWithString:#"http://www.something.com/myFile.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:pdfURL];
[webView loadRequest:request];
[self.view addSubview:webView];

Displaying a .doc file with custom margins

This piece of code dispalys a document in a scrollable UIWebView:
- (void)viewDidLoad
{
[super viewDidLoad];
_myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 760)];
NSURL *myUrl = [NSURL URLWithString:#"http://pathToDoc/myDoc.doc"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myUrl];
[_myWebView loadRequest:myRequest];
[self.view addSubview:_myWebView];
}
This works fine except when trying to display a landscape document which has been created with custom margins which are smaller than standard.
The result is the contents of the right-hand edge of the document are chopped off.
Is there any way to display the whole document?
Well, after several months of frustration with this (can barely believe how long it took!), it turned out to need only a single line of code to solve the problem.
_documentWebView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
Add that just after the last line and suddenly all is well in the world.

ipad orientation problem with webview

I'm creating ipad application. It has just 2 views.
One view has few buttons. On click of a button it will open another view. This view has a webview which shows PDF file. I'm using the following code to show the PDF
- (void)viewDidLoad {
[super viewDidLoad];
NSString* path = [[NSBundle mainBundle] pathForResource:#"mypdf" ofType:#"pdf"];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
}
Now the problem is that, when I change the orientation, whole view is rotating, but the pdf is being disturbed and not rendering properly. how can I avoid this?
As the PDF is having 250 pages, reloading the whole PDF on willRotateToInterfaceOrientation and didRotateFromInterfaceOrientation will delay the display.
How to avoid this situation.
There has to be a way a better to avoid/fix this, for now i just read the y scroll position with:
int scrollPosition = [[webView stringByEvaluatingJavaScriptFromString:#"window.pageYOffset"] intValue];
Then reloaded the document in:
(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
and then set the scroll position again with:
[webView stringByEvaluatingJavaScriptFromString: [NSString stringWithFormat:#"scrollTo(0,%d)",scrollPosition];

Resources