如何在MacGap中打印HTML元素的内容?

Jos*_*iah 9 macos cocoa objective-c webview macgap

我正在使用MacGap2创建一个WebView应用程序,我希望能够打印HTML元素的内容(具有在Safari/Preview /等中看到的打印预览).

我一直在关注WebUIDelegate的webView:printFrameView以及在Cocoa中打印WebView的整个内容,而不仅仅是显示 - 但我很难将它们放在一起,因为我是Objective-C/Cocoa的新手.

如果我想要这样的方法(如果打印预览有效,则不需要选项):

MacGap.print([HTMLelement], [options]);

// Example usage
var el = document.getElementById('view');

// Or if not element, send as HTML string? (with inline CSS)
// el = el.innerHTML;

MacGap.print(el, { printBackgrounds: true, landscape: false });
Run Code Online (Sandbox Code Playgroud)

我需要添加到我的MacGap类/命令中?

App.h:

- (void) print:(NSString*)printString;
Run Code Online (Sandbox Code Playgroud)

App.m:

- (void) print:(NSString*)printString {
    // ???
} 
Run Code Online (Sandbox Code Playgroud)

Mar*_*ark 0

我没有使用 MacGap2 的经验,我在 uiwebview 而不是 webview 上测试了这个,但我认为它应该仍然可以从 webview 获取 html 字符串。

- (void) print:(NSString*)printString 
{
     NSString * pstrViewHTML= [myWebView stringByEvaluatingJavaScriptFromString:@"function getView(){return document.getElementById('view');} getView();"];
    // Do something with html string.
}
Run Code Online (Sandbox Code Playgroud)