Many news and information sites offer a way to generate pages that are easy to print, the resulting layout of the page is more conducive to the printing output of the printer, which makes it easier for us to print the content we need directly from the page, without having to worry about formatting, or pasting it into a text editor. However, I do not see how many sites explain how these are implemented, here I provide a small piece of code--the use of PHP to achieve the production of easy to print pages is not as difficult as it is, I hope to help.
What do we need to do to generate pages that are easy to print? This depends primarily on the characteristics of your site and the layout features you want to generate, but there are some basic processes that need to be done:
1, page width-the width of the generated page must be limited to print A4 paper, about 630 pixels wide page.
2, page background color-for the beautiful, many pages use a different background color and background picture, but as the page to be printed, the most appropriate effect or white background black word for good.
3, advertising strip-Remove the ads on the page
4, the background color of the table-we often use color in the table to emphasize information and titles, these must also be removed.
5, Links--The hyperlinks on the page must also be changed to make the URLs visible, for example: <a href=http://www.gbdirect.co.uk/>GBDirect</a> should be displayed as Gbdirect (http:// www.gbdirect.co.uk/)
6, Menu-menu is the most difficult to be banned, however, if your page is built using templates, then the easiest way is to swap with a template that is easy to print without a menu.
All of the methods that make it easy to print a page are very simple, and when you need to implement it, you can put it in a Web page with the following code:
?
To get the relative path of a file from an environment variable
$page =substr ($SCRIPT _name,1);
Displays an icon and connects to printer friendly Pages
Easy to print a page's build program pfp.php
?>
<a href= "pfp.php?page=<?= $page?>" >;
alt= "Click here to produce a printer friendly page" >
<font face= "Arial, Helvetica" size= "2" >
Printer Friendly Version
</font>
</a>
Pass the name of the current page to the pfp.php program, which uses PHP's "file" function to handle the page as a string. When this page is loaded, the program can add, overwrite, or delete HTML fragments.
<tr>
<TD valign= "Top" >
?
Check if the filename for the page exists
if (!file_exists ("$page. Inc")
{
echo "<strong>error-the page <?= $page?>".
"Does not exist on this site.</strong>";
}
Else
{
Get the content of the page and put it in a string
$fcontents = Join (' ", File (" $page. Inc ");
Ignore the color attribute and convert to ' ignore ' instead of ' color '
$fcontents = ereg_replace (' Color ', ' ignore ', $fcontents);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.