2012-11-20 34 views
0

我刚刚开始使用PHP,并且无法让我的页面结果正确打印。我从index.php调用下面的页面。如果我在监视器上显示页面,但看起来不错,但是当我打印该页面并且页面不止一页时,页面末尾的部分被切断并继续在第二页上。我正在寻找一种方式,以便在打印页面时查看该部分(每个项目编号)是否适合该页面中的整个部分(修复desc,常见原因等)。如果没有,那就在下一页打印。在PHP中添加逻辑打印

我还包括了CSS文件。基本上它是强制页面宽度适合信纸尺寸的纸张。先谢谢你。

<?php include_once $_SERVER['DOCUMENT_ROOT'] . 
    '/fms/includes/helpers.inc.php'; ?> 
<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <title>Print Repair Form</title> 
    <link rel='stylesheet' type='text/css' href='/fms/css/letter-size.css' /> 
</head> 
<body> 
    <div id="page-wrap"> 
    <table> 
    <tr> 
      <td rowspan = "3" id="logo"><a href="/fms/"><img src="/fms/images/flex_no_address_256.jpg" /></a></td> 
     <td rowspan = "3" id="address">Address<br /> 
     City, State Zipcode <br /> 
     Phone number <br /> 
     website address 
     </td> 
     <td> 
     <table> 
     <tr> 
       <td id="repairinfo" class="theading" colspan = "2">Repair Detail</td> 
     </tr> 
     <tr> 
      <td><?php htmlout($custno); ?></td> 
      <td width="100px">WO: <?php htmlout($wonum); ?></td> 
     </tr> 
     <tr> 
      <td><?php htmlout($custname); ?></td> 
      <td></td> 
     </tr> 
     </table> 
     </td> 
    </tr> 
    </table> 
    <br /> 
    <?php foreach($items as $item): ?> 
    <table border ="1"> 
    <tr> 
     <td class="theading">Type of Repair</td> 
      <td class="theading">Repair ID</td> 
     <td class="theading">Fault Picture</td> 
    </tr> 
    <tr> 
     <td class="tablepadding"><?php htmlout($item['repairtype']); ?></td> 
     <td class="tablepadding"><?php htmlout($item['itemno']); ?></td> 
     <td rowspan="7" align="center"> 
      <img src="/fms/images/wo_items/<?php htmlout($item['filename']); ?>"   width="256" /> 
     </td> 
    </tr> 
    <tr> 
     <td class="theading" colspan="2">Repair Description</td> 
    </tr> 
    <tr> 
     <td class="tablepadding" colspan="2"><?php htmlout($item['repairdesc']); ?> 
     </td> 
    </tr> 
    <tr> 
     <td class="theading" colspan="2">Common Causes</td> 
    </tr> 
    <tr> 
     <td class="tablepadding" colspan="2"><?php htmlout($item['commoncause']); ?> 
     </td> 
    </tr> 
    <tr> 
     <td class="theading" colspan="2">Preventive Measures and Maintenance</td> 
    </tr> 
    <tr> 
     <td class="tablepadding" colspan="2"><?php htmlout($item['maintenance']); ?> 
     </td> 
    </tr> 
     </table> 
     <br /> 
     <?php endforeach; ?> 
    </div> 
</body> 
</html> 

CSS:

* { margin: 0; padding: 0;} 
body { 
    font: 12px/1.4 Georgia, serif; 
} 

a img { 
    border: none; 
} 
#page-wrap { 
    width: 800px; 
    margin: 0 auto; 
} 

table { 
    width:100%; 
} 

#logo { 
    width: 256px; 
} 

#address { 
    width: 170px; 
} 

#repairinfo { 
    border-bottom: solid 1px; 
    text-align: center; 
} 

.theading { 
    font-weight: bold; 
    padding: 3px; 
} 

table tr td.tablepadding { 
    padding: 3px; 
} 

回答

0

它应该通过CSS和PHP来实现,尽管你可以使用PHP以及变通办法,谷歌的CSS媒体。

有您打印的CSS一些技巧:http://slodive.com/web-development/css-print-page-tricks/

不能给你具体的细节,因为我还没有制定太多与印刷,但所有涉及到的测试,适合对总高度纸,并寻找在PHP中的措施(也许线?),所以如果大小比你设置的大,它会创建另一个表。

您也可以使用Javascript,因为您可以检测元素的高度(例如表格的高度),并在达到最大高度时调用某个函数。


而且我希望你不使用的表,如果它不是完全necesary,这是一个非常老派的做法和麻烦的修改,以跨浏览器的多个不同的行为,并与更多的unnecesary代码建议。