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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.