I'm creating a WebView app with MacGap2 and I'd like to be able to print the contents of an HTML element (with a print preview like you would see in Safari/Preview/etc).
我正在使用MacGap2创建一个WebView应用程序,我希望能够打印HTML元素的内容(具有在Safari / Preview / etc中看到的打印预览)。
I've been looking at WebUIDelegate's webView:printFrameView as well as Printing Entire Contents of WebView in Cocoa, Not Just Displayed - but I'm having a hard time putting it all together as I'm new to Objective-C/Cocoa.
我一直在关注WebUIDelegate的webView:printFrameView以及在Cocoa中打印WebView的整个内容,而不仅仅是显示 - 但我很难将它们放在一起,因为我是Objective-C / Cocoa的新手。
If I wanted a method like this (options not necessary if print preview works):
如果我想要这样的方法(如果打印预览有效,则不需要选项):
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 });
What would I need to add to my MacGap Classes/Commands?
我需要添加到我的MacGap类/命令中?
App.h:
- (void) print:(NSString*)printString;
App.m:
- (void) print:(NSString*)printString {
// ???
}
1 个解决方案
#1
0
I dont have experience with MacGap2 and I tested this on a uiwebview not a webview, but I think it should still work to get the html string from the webview.
我没有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.
}
#1
0
I dont have experience with MacGap2 and I tested this on a uiwebview not a webview, but I think it should still work to get the html string from the webview.
我没有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.
}