printer friendly
Moderator: General Moderators
-
sirTemplar
- Forum Commoner
- Posts: 65
- Joined: Wed Dec 18, 2002 1:57 am
printer friendly
i have a form that searches a database. of course when after a search they see an output page. it work well but the output right now is not printer friendly. how do i create a printer friendly output of the result of the page? i tried to use a script i found on the net but it outputs all the data of from the database and not only the result. thanks.
- andym01480
- Forum Contributor
- Posts: 390
- Joined: Wed Apr 19, 2006 5:01 pm
That's normally done by CSS stylesheet - I create two style sheets for my pages - the normal one is style.css and the print one is print.css. The print one only has the content - no menus etc and is in printable colours and set up to look good on paper. They are called in the head section. So on screen a browser picks style.css but when you press print the browser uses print.css for the layout.
Compare the two at http://www.thebridgechurch.co.uk to see how they work, which uses a fairly simple 3 column floating layout, that works well in Firefox and IE.
Code: Select all
<style type="text/css" media="screen">@import "style.css";</style>
<link rel="stylesheet" type="text/css" media="print" href="print.css" />-
sirTemplar
- Forum Commoner
- Posts: 65
- Joined: Wed Dec 18, 2002 1:57 am
- andym01480
- Forum Contributor
- Posts: 390
- Joined: Wed Apr 19, 2006 5:01 pm
No not at all! The clever thing about doing it using css is that you get rid of that very irritating printer friendly page link, that naff websites have! Because it is becomes automatic by good web-developing!
When a user presses print or <file><print> in their browser, it reloads the page to send to the printer automatically using the print style sheet. Without the user having to do anything. You would have written a print style sheet that makes the page printer friendly.
You just have to do a bit of work when coding your stylesheets and then make sure the stylesheet calls above appear in the header! I'm assuming you are using css anyway.
What you need to do is write a second style sheet stripping out the div classes that cover navigation, making the backgrounds white... etc and making the content div so it fits on a printer in portrait. Experiment until it is right.
I learned how by putting this tutorial into practice
http://www.alistapart.com/articles/goingtoprint/
Have fun!
BTW if you are not using css and style sheets why not?!!!!
When a user presses print or <file><print> in their browser, it reloads the page to send to the printer automatically using the print style sheet. Without the user having to do anything. You would have written a print style sheet that makes the page printer friendly.
You just have to do a bit of work when coding your stylesheets and then make sure the stylesheet calls above appear in the header! I'm assuming you are using css anyway.
What you need to do is write a second style sheet stripping out the div classes that cover navigation, making the backgrounds white... etc and making the content div so it fits on a printer in portrait. Experiment until it is right.
I learned how by putting this tutorial into practice
http://www.alistapart.com/articles/goingtoprint/
Have fun!
BTW if you are not using css and style sheets why not?!!!!
- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
put the <!-- startprint --> from where you want to start print in the page and put <!-- stopprint --> where you want to stop printing. Put the link print.php?title=some title anywhere in the page.
<form name="form1" action="">
<input name="button" type="button" value="Print" onClick="window.print();">
</form>
Hope this might help you !
Cheers,
Dibyendra
Code: Select all
print.phpCode: Select all
<?php
/*
1. Save this script in the root of the site for simplicity.
2. Place <!-- startprint --> somewhere in your HTML page where you consider
it to be the start of printer friendly content, and <!-- stopprint --> goes at the end
of that same content.
3. You place a link to phprint.php anywhere on the HTML page (preferably outside the printed content,
like this: <a href="/print.php?title=page title">Print this page</a>
- or however you like, just as long as you link to this script.
*/
// let's turn errors back on so we can debug if necessary
error_reporting(1);
//Do you want to strip images from the printable output?
// If no, change to "no". Otherwise, images are stripped by default.
header('Content-Type: text/html; charset=utf-8');
$stripImages = "yes";
//what's the base domain name of your site, without trailing slash?
// Just the domain itself, so we can fix any relative image and link problems.
$baseURL="http://domain.com";
// That's it! No need to go below here. Upload it and test by going to yoursite.com/page.php
// (The page containing a the two tags and a link to this script)
// -----------------------------------------------------
$refpage = (phpversion() > "4.1.0") ? $_SERVER['HTTP_REFERER'] : $HTTP_SERVER_VARS['HTTP_REFERER'];
// $refpage = (phpversion() > "4.1.0") ? $_SERVER[HTTP_REFERER] : $HTTP_SERVER_VARS[HTTP_REFERER];
$startingpoint = "<!-- startprint -->";
$endingpoint = "<!-- stopprint -->";
// let's turn off any ugly errors for a sec-
error_reporting(0);
// $read = fopen($refpage, "rb") ... may work better if you're using NT and images
$read = fopen($refpage, "r") or die ("<br />Sorry! There is no access to this file directly. You must follow a link. <br /><br />");
$value = "";
while(!feof($read)){
$value .= fread($read, 16000); // reduce number to save server load
}
fclose($read);
$start= strpos($value, "$startingpoint");
$finish= strpos($value, "$endingpoint");
$length= $finish-$start;
$value=substr($value, $start, $length);
function i_denude($variable){
return(eregi_replace("<img src=[^>]*>", "", $variable));
}
function i_denudef($variable){
return(eregi_replace("<font[^>]*>", "", $variable));
}
function strip_link($variable){
$variable=eregi_replace("<a href[^>]*>", "", $variable);
return(eregi_replace("</a>", "", $variable));
}
$PHPrint = ("$value");
if ($stripImages == "yes") {
$PHPrint = i_denude("$PHPrint");
}
$PHPrint = i_denudef("$PHPrint");
$PHPrint = strip_link("$PHPrint");
$PHPrint = eregi_replace( "</font>", "", $PHPrint );
$PHPrint = stripslashes("$PHPrint");
// echo "<base href=\"$baseURL\">";
echo $PHPrint;
//echo "<br/><br/>Page printed from: <br />" . " $refpage ";
?>
<input name="button" type="button" value="Print" onClick="window.print();">
</form>
Code: Select all
end of Print.phpCheers,
Dibyendra