Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread Display Modes
Old Jan 16, 2013, 02:56 PM   #1
macrumors newbie
Join Date: Jan 2013
WebView scrolling problems

I'm relatively new to osx and objective C programming and need some help getting a WebView to work.

I am trying to write a program to generate math worksheets and save them to pdf files.

The easiest way I have found to handle the equations is the generate latex and then load them into a webview and have them rendered using MathJax. this part works fine. I found a simple method to generate the pdf files from the webview as well.

Because of the pdf generation method I am using, I find it easiest to use two webviews, one for the problems and one for the answers, each of which will be saved to a different pdf file.

The problem I am having is finding a good way to display both views without taking up the whole screen and more making them full size.

I was thinking something like a tab view, with a different tab for each webview, or a scroll view with one web view "beneath" the other.

No matter what I do the layout never works - the scrolling is always messed up.

I want to make the webviews full a4 paper size for convenience, but put them into a smaller window in a scrollview or tab view and then be able to scroll around the web view that way (allowing for resizing of the outer view to display more of the webview if the user wants).

But nothing I do allows me do this.

I am using xcode interface builder.

I am open to other clever suggestions as well for how to have a manageable display for the two web views, or how I can put them in a scrollview or tabview and get the behavior I want.


(added later)
It occurred to me it might be helpful to show the code I am using for generating the pdf files. I found this code after a lot of searching around and it was very simple to use and does not create an "image" of the webview, which looks bad in general.

My problem would also be solvable if I could put both pages in one webview and then save that to two separate pages in a pdf later, but I have not been able to figure out how to do this - how to find where the page break should occur and then how to save each webview "page" to a pdf page.

//save webview to pdf
- (IBAction)savePDF:(id)sender {
    NSRect screenRect = self.myWebView.frame;
    NSRect a4Rect = CGRectMake(0,0,595,842);
    [myWebView setFrame:a4Rect];
    NSData *pdfData = [[[[myWebView mainFrame] frameView] documentView] dataWithPDFInsideRect:self.myWebView.frame];
    PDFDocument *document = [[PDFDocument alloc] initWithData:pdfData];
    [self setSaveDirectory];
    NSString *fileName = [NSString stringWithFormat:@"%@/testing.pdf",saveDir];
    NSLog(@"Save location: %@",fileName);
    [myWebView setFrame:screenRect];
    [document writeToFile:fileName];

Last edited by Taub; Jan 17, 2013 at 12:27 AM. Reason: Adding some more useful information
Taub is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Webview didFinishLoadForFrame DennisBlah Mac Programming 6 Mar 14, 2014 11:00 AM
WebView does not respond to scrollToPoint: Blakeasd Mac Programming 0 Dec 3, 2013 06:35 PM
Can't Detect Events on a WebView Blakeasd Mac Programming 5 Nov 27, 2013 09:17 PM
has the scrolling and ui lag problems in rmbp 13 been solved? lesliewj OS X Mavericks (10.9) 0 Jun 12, 2013 10:34 AM
Natural scrolling for trackpads, old scrolling for mouses? JesperA OS X 10.8 Mountain Lion 1 Nov 29, 2012 11:01 PM

Forum Jump

All times are GMT -5. The time now is 08:13 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2015, MacRumors.com, LLC