?
Solved

printer friendly pages

Posted on 2003-03-06
2
Medium Priority
?
263 Views
Last Modified: 2008-03-10
Im trying to make printer friendly pages using PHP, I got a free script but it doesnt work properly because the images dont show up properly! Also I have used layers does this mean that I wont be able to move the content that I want to print to the left. I have a nav bar o the left which I want to have dissappear and the content move to where it once was.
This is the free code I currently have.

<?php
/*PHPrint - This file is phprint.php
Make any Page Printer Friendly! Version 2.0 - With error handling
Copyright by MikeNew.Net, Notice must stay intact
Any improvements to this script are welcome: www.mikenew.net/contact.asp 
************
Legal: MikeNew.Net is not responsible for any damages caused
by use of this script. (Not likely that it will. Hasn't yet.)
This script will make your pages printer friendly.
Optionally, it will strip images as well. (Instructions for that below)
// After installation, you can remove text from here down to the next: 8< ---->
// Back up/copy this file first.
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="/phprint.php">Print this page</a>
- or however you like, just as long as you link to this script. */
// If you've already tested, you can remove the text from here up to the other: 8< ---->
//Do you want to strip images from the printable output?
// If no, change to "no". Otherwise, images are stripped by default.
$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://www.caladan.co.uk";
// That's it! No need to go below here. Upload it and test by going to yoursite.com/page.php
// (The page containing the two tags and a link to this script)
// -----------------------------------------------------
$startingpoint = "<!-- startprint -->";
$endingpoint = "<!-- stopprint -->";
// let's turn off any ugly errors for a sec so we can use our own if necessary...
error_reporting(0);
// $read = fopen($HTTP_REFERER, "rb") ... this line may work better if you're using NT, or even FreeBSD
$read = fopen($HTTP_REFERER, "r") or die("<br /><font face=\"Verdana\">Sorry! There is no access to this file directly. You must follow a link. <br /><br />Please click your browser's back button. </font><br><br><a href=\"http://miracle2.net/\"><img src=\"http://miracle2.net/i.gif\" alt=\"miracle 2\" border=\"0\"></a>");
// let's turn errors back on so we can debug if necessary
error_reporting(1);
$value = "";
while(!feof($read)){
$value .= fread($read, 10000); // 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));
}
$PHPrint = ("$value");
if ($stripImages == "yes") {
$PHPrint = i_denude("$PHPrint");
}
$PHPrint = i_denudef("$PHPrint");
$PHPrint = str_replace( "</font>", "", $PHPrint );
$PHPrint = stripslashes("$PHPrint");
echo "<base href=\"$baseURL\">";
echo $PHPrint;
// Next line is invisible except to SE crawlers, please don't remove. Thanks! :)
echo "<br><a href=\"http://miracle2.net/\"><img src=\"http://miracle2.net/i.gif\" ";
echo "alt=\"miracle 2\" border=\"0\"></a>";
echo "<br/><br/>This page is printed from: $HTTP_REFERER";
flush ();
?>

Does anyone have any suggestions, I am not familiar with PHP, so if anyone can help, it would be very appreciated, thanks in advance.
0
Comment
Question by:georgie82
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
alfarod earned 200 total points
ID: 8087285
I did that once with layers. I had hidden the navigation layers and moved the content layer up and left before printing. After printing I had returned to the previous positions.

I did that with javascript. Use the onClick event on the print button to call a javascript funtion.

In that functions you keep the layer's position, then you print your page, and after that you restore the previous position.

a simple example:

the button:
<input type="button" value="Print" onClick="printContent()">


the function:

function printContent()
{
  // hide the navigation layers
  document.all.layerHeader.style.visibility = "hidden";
  document.all.layerMenu.style.visibility = "hidden";

  // keep the previous position
  layerTop = document.all.layerName.style.top;
  layerLeft = document.all.layerName.style.left;

  // set the new position
  document.all.layerName.style.top = 0;
  document.all.layerName.style.left = 0;

  // print the page
  print();

  // restore the previous position
  document.all.layerName.style.top = layerTop ;
  document.all.layerName.style.left = layerLeft ;

  // show the hidden layers
  document.all.layerHeader.style.visibility = "visible";
  document.all.layerMenu.style.visibility = "visible";
}


0
 

Author Comment

by:georgie82
ID: 8088399
Thanks alfarod, I havent tried the code you had given me because I had already started putting a lot of effort into using CSS to resolve the problem, but thanks anyway! It looks like it could be good for future reference though!
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question