WebView scrolling problems

Discussion in 'Mac Programming' started by Taub, Jan 16, 2013.

  1. Taub, Jan 16, 2013
    Last edited: Jan 16, 2013

    Taub macrumors newbie

    Jan 16, 2013
    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];

Share This Page