A different approach to print whatever is in your screen.
Yii 1.1 or above jQuery
Extract it under your /extensions directory.
Declare the largest element as the 'element', and just add the unneeded DIVs or classes under exceptions.
Edit the mprint.css or/and add css to satisfy your taste.
Debug mode is added so that you can play with the the page that you will be printing.If you enable this feature, you can set the dimensions of the mPrint section (which appears at the bottom of the page) by overriding dbgWidth and dbgHeight, which defaults are set to 100%. Printing will not proceed if debug mode is enabled.
<?php $this->widget('ext.mPrint.mPrint', array( 'title' => 'title', //the title of the document. Defaults to the HTML title 'tooltip' => 'Print', //tooltip message of the print icon. Defaults to 'print' 'text' => 'Print Results', //text which will appear beside the print icon. Defaults to NULL 'element' => '#page', //the element to be printed. 'exceptions' => array( //the element/s which will be ignored '.summary', '.search-form' ), 'publishCss' => true, //publish the CSS for the whole page? 'visible' => Yii::app()->user->checkAccess('print'), //should this be visible to the current user? 'alt' => 'print', //text which will appear if image can't be loaded 'debug' => true, //enable the debugger to see what you will get 'id' => 'print-div' //id of the print link )); ?>
- appended the id in registerScript so as to work on multiple print links on the page (thanks tommo)
- used the element declared by the user instead of adding the class mprint (thanks Trejder)
- added the property id, which will serve as the id attribute of the print link
- added the property cssFile which is intended to replace css so as to avoid confusion for those who are used to in cssFile variable (besides, it is more definitive since it is a property for a css file)
- added property dbgHeight and dbgWidth, which will be the size of the debug portion
- added the property timeOut which will tell how many seconds before the iframe disappears. This will only be usable if debug is set to false
- added the method mCssFile which will manage what value to use between css and cssFile property
- made some adjustments with the js
- fixed the code so as to make use of $cssFile variable more effectively (thanks tydeas_dr)
- added the variable 'debug' so that the result can be seen and checked first before sending it out to the printer
- enhanced the passsing of parameters to the js by using json_encode function
- enhanced the js code (added $.fn.print.defaults)
- fixed some bugs found when using FF
- added the property 'alt' (string), which is the text that will appear if the image is not available
- modified the way the property is being checked from isset() to strlen().
- enhanced the way in producing the image tag and used the Yii-way instead of manually creating it.
- enhanced (somehow) the documentation.
- added the property 'showIcon' (bool), which tells whether to include the image in the link or not
- added the property 'image' (string), which tells the widget what icon to use. With this, different icons can be used in different widget calls (for example, one grid icon to print the datagrid results, and one calendar icon to print the calendar div). It will only be rendered if the properties 'visible' and 'showIcon' are set to 'true'. Default value is 'printer.png'
- added the property 'visible' (bool), which dicates the visibility of the printing link
- modified some lines of codes to make it more clearer
- fixed the way the JS file creates the iFrame (where
<head>is inside the
- added the execCommand in mPrint.js to fix IE7 and IE8 issue on printing banners
fixed the bug 'Missing argument 2 for CClientScript::registerCss()' by replacing registerCss with registerCssFile (thanks to joblo)
modified the property 'exemptions' to 'exceptions' for a more definitive term (thanks Gustavo)
added the property 'publishCss' (bool), which will dictate whether to register the CSS file for the whole page (for the benefit of CTRL+P).
- initial release
JQuery print code came from: http://www.bennadel.com