Jump to content

Print Preview


lsy

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/201601-print-preview/#findComment-1057620
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/201601-print-preview/#findComment-1057621
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/201601-print-preview/#findComment-1057626
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/201601-print-preview/#findComment-1059940
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/201601-print-preview/#findComment-1059955
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.