lsy Posted May 13, 2010 Share Posted May 13, 2010 How can i call a print Preview function as same as File->Print Preview from a button? Quote Link to comment Share on other sites More sharing options...
ignace Posted May 13, 2010 Share Posted May 13, 2010 Create a print stylesheet in your main website you set: <link href="style.css" media="screen" .. <link href="style.print.css" media="print" .. When the user clicks the print preview button you direct them to a PHP page that loads the article and you set: <link href="style.print.css" media="screen" .. This method makes sure that the user always is able to view a print preview either through it's browser File > Print Preview or through your own mechanism. Quote Link to comment Share on other sites More sharing options...
lsy Posted May 13, 2010 Author Share Posted May 13, 2010 Create a print stylesheet in your main website you set: <link href="style.css" media="screen" .. <link href="style.print.css" media="print" .. When the user clicks the print preview button you direct them to a PHP page that loads the article and you set: <link href="style.print.css" media="screen" .. This method makes sure that the user always is able to view a print preview either through it's browser File > Print Preview or through your own mechanism. sorry, i'm very new in php... can you pls explain in step by step or you have any full sample provide? i'm really appreciate if you can help. Quote Link to comment Share on other sites More sharing options...
Sergey Popov Posted May 13, 2010 Share Posted May 13, 2010 lsy, unfortunately you can not invoke print or print preview from PHP. This is a server side language. It can generate HTML pages, that browser will show. You can use Javascript to Print page, like this: <body onload="window.print()"> But there is no simple way to print preview with Javascript either. What ignace suggest is that you create a print stylesheet, so that when someone want to print your webpage, it uses printer friendly styles. But user still need to click on File -> Print Preview in browser. There are several solutions available in Javascript, so you may need to go to appropriate board, or google javascript print preview. Quote Link to comment Share on other sites More sharing options...
ignace Posted May 13, 2010 Share Posted May 13, 2010 JavaScript is not the best solution as you most likely want this to work even when JS is disabled. More and more users like my Dad have NoScript installed which disables JS for any websites they don't trust. Quote Link to comment Share on other sites More sharing options...
lsy Posted May 18, 2010 Author Share Posted May 18, 2010 JavaScript is not the best solution as you most likely want this to work even when JS is disabled. More and more users like my Dad have NoScript installed which disables JS for any websites they don't trust. so what method you would suggest? i'm urgently looking for this features. pls helps. Quote Link to comment Share on other sites More sharing options...
ignace Posted May 18, 2010 Share Posted May 18, 2010 Create a print stylesheet in your main website you set: <link href="style.css" media="screen" .. <link href="style.print.css" media="print" .. When the user clicks the print preview button you direct them to a PHP page that loads the article and you set: <link href="style.print.css" media="screen" .. This method makes sure that the user always is able to view a print preview either through it's browser File > Print Preview or through your own mechanism. With "When the user clicks the print preview button you direct them to a PHP page" I mean: <a href="print.php?articleID=$id">Print this article</a> print.php has only the print stylesheet loaded (which will make it look the same as the print preview). Remember to include your print stylesheet on all pages as the user may aswell just press File > Print Preview. Quote Link to comment Share on other sites More sharing options...
lsy Posted May 18, 2010 Author Share Posted May 18, 2010 i'm looking exactly like File-> Print preview, which will tell the page no. so that i can select which page to be print. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.