I also found this function, however aWindow and aTargetWindow have to be the same. And when they are, it turns the docShell of that window to print preview, instead of opening in new window, which is really weird.
function noida_printpreview(aWindow, aTargetWindow) {
var wbp = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebBrowserPrint);
var listener = {
onLocationChange: function(webProgress, request, location, flags) {},
onProgressChange: function(webProgress, request, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) {},
onSecurityChange: function(webProgress, request, state) {},
onStateChange: function(webProgress, request, stateFlags, status) {},
onStatusChange: function(webProgress, request, status, message) {},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIWebProgressListener) || iid.equals(Ci.nsISupportsWeakReference)) {
return this;
}
throw Cr.NS_NOINTERFACE;
}
}
//Services.prefs.setBoolPref('print.show_print_progress', false);
//XXX I would have thought this would work, instead I'm forced to use prefs service
//wbp.globalPrintSettings.showPrintProgress = false;
wbp.printPreview(wbp.globalPrintSettings, aTargetWindow, listener);
//Services.prefs.clearUserPref('print.show_print_progress');
}
However this is the closest I get, im thinking ill load a new tab instead ofa hidden iframe, and then use this function to convert its docShell to the print preview. However the print preview has no GUI elements, and back button doesnt work. So need help on this please.