OSX将WebView内容保存为多页PDF

use*_*685 7 pdf macos xcode webview multipage

我正在使用xcode开发OSX应用程序.我有一个工作的WebView,它使用MathJax来显示方程式(以及普通的html内容).我正在为数学老师创建一个数学工作表生成器.

我一直在搜索网络,试图找出有关将比赛保存到pdf的详细信息,但还没有想到这一切.

我目前正在使用以下代码将WebView成功保存为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];
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是它根据WebView的竞赛创建了一个巨大的pdf页面.我希望能够引入分页符.

我总会有两页,一页是问题,另一页是答案.现在,我知道如何执行此操作的唯一方法是将它们全部放在WebView上,然后尝试将其保存为PDF并找到引入分页符的方法.

我怎样才能做到这一点?