Sometimes you want to print a receipt or a some kind of voucher, you have two choice:
- Generate a PDF document of your content .
- Send it directly to the printer .
For me i find it much easily to use the second choice, because generating a PDF via the code is much heavier and needs to add libraries or any type of external code .
So here is a simple example using Jquery and a specefic jquery plugin jquery.PrintArea.js .
<html> <script src="jquery-1.9.0.js" type="text/JavaScript" language="javascript"></script> <script src="jquery.PrintArea.js" type="text/JavaScript" language="javascript"></script>
<head><script type="text/javascript" > $(document).ready(function() { $("#button").click(function() { //$(this).hide(); $("#myPrintDiv").printArea(); }); }); </script> </head> <body> <div id="myPrintDiv"> test print div using jquery </div> <form> <input type="button" name="print" id="button" value="Print" /> </form> </body> </html>
Please test it and give us your feedback .
Thank you very much
Commentaires
Enregistrer un commentaire