OSX save WebView content to multipage PDF
Asked Answered
T

0

7

I am working on an OSX app with xcode. I have a working WebView that uses MathJax to display equations (as well as normal html content). I am creating a math worksheet generator for math teachers.

I have been searching the web a lot trying to find out details about saving the contest to a pdf, but haven't figured it all out.

I am currently using the following code which successfully saves the WebView to a pdf:

- (IBAction)savePDF:(id)sender {
    NSData *pdfData = [[[[myWebView mainFrame] frameView] documentView] dataWithPDFInsideRect:[[[myWebView mainFrame] frameView] documentView].frame];
    PDFDocument *document = [[PDFDocument alloc] initWithData:pdfData];

    [self setSaveDirectory];

    NSString *fileName = [NSString stringWithFormat:@"%@/testing.pdf",saveDir];
    NSLog(@"Save location: %@",fileName);

    [document writeToFile:fileName];
}

The problem I am having is that it creates one giant pdf page based on the contest of the WebView. I would like to be able to introduce a page break.

I will always have two pages, one for the problems, and one for the answers. Right now the only way I know how to do this is to put them all in a row on the WebView and then try and save it to a PDF and find some way to introduce a page break.

How can I do this?

Tinner answered 13/1, 2013 at 13:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.