Another option to consider is to render the image component or PDF. Although the pop-up / print option is good, some browsers do not print correctly. They tend to ignore background images, certain css properties, etc. To make the component print exactly as it appears in the popup, I ended up writing server-side code to convert html to image.
This is what the client code looks like:
print: function(el){ var waitMask = new Ext.LoadMask(Ext.getBody(), {msg:"Please wait..."}); waitMask.show(); //Parse current url to set up the host and path variables. These will be //used to construct absolute urls to any stylesheets. var currURL = window.location.href.toString(); var arr = currURL.split("/"); var len = 0; for (var i=0; i<arr.length; i++){ if (i<3) len+=(arr[i].length+1); } var host = currURL.substring(0, len); if (host.substring(host.length-1)=="/") host = host.substring(0, host.length-1); var path = window.location.pathname; if (path.lastIndexOf("/")!=path.length-1){ var filename = path.substring(path.lastIndexOf("/")+1); if (filename.indexOf(".")!=-1){ path = path.substring(0, path.lastIndexOf("/")+1); } else{ path += "/"; } } //Start constructing an html document that we will send to the server var html = ('<html><head>'); html += ('<title>' + document.title + '</title>'); //Insert stylesheets found in the current page. Update href attributes //to absolute URLs as needed. var links = document.getElementsByTagName("link"); for (var i=0; i<links.length; i++){ var attr = links[i].attributes; if (attr.getNamedItem("rel")!=null){ var rel = attr.getNamedItem("rel").value; var type = attr.getNamedItem("type").value; var href = attr.getNamedItem("href").value; if (href.toLowerCase().indexOf("http")!=0){ if (href.toString().substring(0, 1)=="/"){ href = host + href; } else{ href = host + path + href; } } html += ('<link type="' + type + '" rel="' + rel+ '" href="' + href + '"/>'); } } html += ('</head><body id="print">'); html += (el.dom.innerHTML); html += ('</body></html>'); //Execute AJAX request to convert the html into an image or pdf - //something that will preserve styles, background images, etc. //This, of course, requires some server-side code. In our case, //our server is generating a png that we return to the client. Ext.Ajax.request({ url: "/WebServices/Print?action=submit", method: "POST", rawData: html, scope: this, success: function(response){ var url = "/WebServices/Print?action=pickup&id="+response.responseText; window.location.href = url; waitMask.hide(); }, failure: function(response){ win.close(); waitMask.hide(); var msg = (response.responseText.length>0 ? response.responseText : response.statusText); alert(msg); } }); }
Again, this requires some server-side magic to convert html to image. In my case, I implemented the Print service. Customers send job requests through the send action and retrieve output products through the pickup action.
To convert html to images, I ended up using the free command-line app Capture Web Screen . It only works with windows, and I donβt know how scalable it is at your own risk.
Peter source share