如何使用php代码使网页打印友好


How to make web page print friendly using php code?

我有一个简单的动态网页,它有一个非模拟的报告数据。我想要生成一个报表样式的数据,所以我只想要打印阶段的功能。

有人能告诉我我该怎么做吗?

我在我的页面中尝试了一些代码

<?php
if($mode == 'print') $stylesheet = 'tp.css';
    else $stylesheet = 'style.css';
echo '<link rel="Stylesheet" href="'.$stylesheet.'" type="text/css" />';
?>
<a href="<?php echo $_SERVER['PHP_SELF'] . '?mode=print'; ?>">Printer friendly version</a>

尝试更改样式表,但遇到不同的问题。

我强烈要求在McaGurus.com 上为访客打印我的网站页面

提前谢谢。

您可以使用普通方法在页面中包含样式表,但添加media属性来定义其用途。

<link href='screen.css' rel='stylesheet' media="screen" type='text/css'>

用于在屏幕上显示您的页面。

<link href='print.css' rel='stylesheet' media="print" type='text/css'>

用于打印。

只需在打印样式的include链接上使用media="print",它将只在颁奖台上使用这些样式。

<link rel="stylesheet" type="text/css" media="print" href="print.css"/>