简体   繁体   English

HTML中的分页符

[英]Page breaks in HTML

So... HTML is still giving me a hard time. 所以... HTML仍然让我很难过。 I have some code that prints out a report of the order for each member, which must be printed as we hand them out to the people delivering the orders. 我有一些代码打印出每个成员的订单报告,当我们将它们交给交付订单的人员时,必须打印出来。 The problem is that the div which contains the page break is a whole bunch of odd sizes, so when I try to print off the report the formatting is very odd. 问题是包含分页符的div是一大堆奇数,所以当我尝试打印报告时,格式很奇怪。 This sometimes results in blank pages being printed, or having an order split between the bottom and top of two different pages. 这有时会导致打印空白页,或者在两个不同页面的底部和顶部之间分配订单。

I would like to figure out how to get each order to print on its own page, right at the top of the page, but that last div is not working the way I want it to. 我想弄清楚如何让每个订单在自己的页面上打印,就在页面的顶部,但是最后一个div没有按照我想要的方式工作。 I have been trying off and on to fix this for weeks; 几个星期以来,我一直在努力解决这个问题。 can someone help me? 有人能帮我吗?

Here is the code for the page: 这是页面的代码:

<style>
.first-time{
    text-align: right;
    color:#fff;
    background: #a00;
}
.page-break {
    display: block;
    page-break-before: always;
}
.title th{
    background: #6c6c6c;
    color:#fff
}
</style>
<script>
</script>
<div class="reports">
<table cellpadding="0" cellspacing="0">
    <?php $count_orders = 0 ?>
    <?php $count_products = 0 ?>
    <?php foreach ($sites as $site): ?>
        <tr>
            <th class="big" colspan="7"><?php echo $site ?></th>
        </tr>
        <?php foreach ($orders as $page_number => $order): ?>
            <?php if ($order['Site']['name'] == $site): ?>
                <tr class="title">
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Address</th>
                    <th>City</th>
                    <th>Email</th>
                    <th>Phone</th>
                    <th>Site</th>
                </tr>
                <tr>
                    <td><strong><?php echo $order['Account']['first_name'] ?></strong></td>
                    <td><strong><?php echo $order['Account']['last_name'] ?>&nbsp;<span style="color:red"><?php echo ($order['Account']['homebound'] == 1)?'(homebound)':'';?></span></strong></td>
                    <td><?php echo $order['Account']['street1'].$order['Account']['street2'] ?></td>
                    <td><?php echo $order['Account']['city']?></td>
                    <td><?php echo $order['Account']['email'] ?></td>
                    <td><?php echo $order['Account']['phone'] ?></td>
                    <td><?php echo $order['Site']['name'] ?></td>
                </tr>
                <tr>
                    <th colspan="6">Product</th>
                    <th>Quantity</th>
                </tr>
                <?php foreach ($order['ProductType'] as $productType): ?>
                    <tr>
                        <td colspan="6"><?php echo $productType['type'] ?></td>
                        <td><?php echo $productType['OrdersProductType']['quantity']*$productType['units'] ?></td>
                    </tr>
                    <?php $count_products++ ?>
                <?php endforeach ?>
                <?php foreach ($order['Coupon'] as $coupon): ?>
                    <tr>
                        <td colspan="6">Coupon</td>
                        <td>-<?php echo $coupon['discount'] ?></td>
                    </tr>
                <?php endforeach ?>
                <?php $count_orders++ ?>
                <input class='account-id' href='/Reports/firstTime' data-sale="<?php echo $order['Order']['sale_id'] ?>" type='hidden' name='data[Account][id]' value="<?= $order['Account']['id'] ?>" />
                <tr></tr>
                <tr><td style='border:none; padding:0;'><div class='page-break'></div></td></tr>
             <?php endif ?>
        <?php endforeach ?>
    <?php endforeach ?>
</table>

Most of that can probably be ignored, but I included it just in case since my HTML coding experience is minimal at best. 其中大部分内容都可能被忽略,但我将其包含在内以防万一,因为我的HTML编码经验最少。 I'm mostly a back-end programmer, but the people using this report don't understand the difference and don't get why I can't just fix it by adding a page break like in Word... 我主要是一个后端程序员,但是使用这个报告的人不理解这个区别,并且不知道为什么我不能通过在Word中添加分页来修复它...

I think you want to use 我想你想用

.page-break {
    display: block;
    page-break-after: always;
}

so it breaks the page after every order not right before that div. 所以它在每个订单之前不在该div之前打破了页面。 I could be wrong though try it and let me know 我试错了但是让我知道

I'm going to go ahead and close this question. 我要继续关闭这个问题。 After talking with my other programmer, we haven't found exactly the root cause of the problem, but we worked around it by separating the table into two tables, one of which was just for the page break. 在与我的其他程序员交谈之后,我们还没有找到问题的根本原因,但我们通过将表分成两个表来解决这个问题,其中一个表只是用于分页符。

This is, we know, terrible coding style. 我们知道,这是一种糟糕的编码风格。 However, it fixed the problem, which leads us to believe that something is grabbing padding from the tables and adding it after the page break. 但是,它解决了这个问题,这使我们相信某些内容正在从表中获取填充并在分页后添加它。 I wasn't able to find what it was, but splitting it fixed it. 我无法找到它是什么,但拆分修复它。

So... bad coding, but it got it fixed. 所以......糟糕的编码,但它得到了修复。 For our little company, that is good enough. 对于我们的小公司来说,这已经足够了。 Thank you for the help. 感谢您的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM