If you are setting the contents of IFrame using javascript document.write()
then you must close the document by newWin.document.close();
otherwise the following code will not work and print will print the contents of whole page instead of only the IFrame contents.
var frm = document.getElementById(id).contentWindow;
frm.focus();// focus on contentWindow is needed on some ie versions
frm.print();