【问题标题】:How to print footer on each printed page?如何在每个打印页面上打印页脚?
【发布时间】:2012-07-09 13:46:48
【问题描述】:

我正在使用 Open Cart 为我的公司开发一个订购系统。
一切都在 PHP 和 HTML 中完成。

我正在尝试修改发票页面以在打印的发票底部包含一个签名行。发票可以根据行/项目的数量延伸到多页,也可以批量处理,以便要打印的一个文档有多个发票(使用循环)。我不是网络开发人员,并且已经达到了我完成项目这一部分的能力的尽头。请给我指点或伪代码示例。

页脚代码:

<style type="text/css">
    .picklistCheck{
        width:15px;
        height:15px;
        border:1px solid #c7c7c7;
        margin:0 auto;
        border-radius:2px;
        box-shadow:inset 0px 0px 2px rgba(0,0,0,0.1);
        font-size:14pt;
    }
    .signature{
        border-bottom-style:solid;
        font-size:14pt;
        page-break-after:always;
    }
    td{
        font-size:14pt;
    }
</style>

<?php
    foreach ($orders as $order) {
        ?>
        //<div>orders go here </div>
        <?php
    }
    include ("footer.php");
?>

【问题讨论】:

    标签: php opencart invoice


    【解决方案1】:

    每次您的逻辑决定在发票中放置分页符时,告诉它也插入以下代码:

    <?php include ("footer.php"); ?>
    

    使用要放置在页脚中的简单 html 创建一个 footer.php 文件。以上代码假设your scriptfooter.php在同一个目录下。

    编辑: 回答您的评论,

    Include PHP.net 的行为与您实际上直接复制粘贴所有代码而不是包含它的行为完全相同。但是每个包含文件都应该有自己的&lt;?php ?&gt; 标签,无论何时需要。如果没有&lt;?php ?&gt; 标签,Control 只会输出它在此处看到的任何内容。

    Footer.php 可以是一个简单的纯 HTML 文件:

    <div id="footer">
        Company XYZ (c)2000-2012 All Copyrights Reserved
        Some other footer text.
    </div>
    

    你也可以把它命名为footer.html,但是如果以后,将来你决定把一些动态数据放在footer里,把.html改成.php就很难了在所有包含写在各种文件中的行中。

    动态页脚示例:

    <div id="footer">
        Company XYZ (c)2000-2012 All Copyrights Reserved
        <?php echo $who_printed." ".$who_authorized; ?>
    </div>
    

    当然这只是一个简单的例子。

    在 html 页面中,您可以通过在外部链接的 .css 文件中使用以下 CSS 代码来强制使用 div:

    #footer{
    text-align: right;
    height: 20px;
    position:fixed;
    margin:0px;
    bottom:0px;
    }
    

    position:fixed; & bottom:0px; 就在这里。它迫使这个"footer" div 始终停留在底部,即使页面被滚动或其他东西。就像 Facebook 将其标题菜单放在顶部和聊天栏底部的方式一样。还可以定义左右属性

    更新:好的,根据你的cmets,这里是示例代码:

    在 CSS 样式部分,使用:

    .signature{
        border-bottom-style:solid;
        font-size:14pt;
        page-break-after:always;
    
        text-align: center;
        height: 20px;
        width: 100%;
        margin:0px auto;
        position:fixed;
        bottom:0px;
    }
    

    所有属性都是不言自明的。 Text-align 使文本居中对齐。 Width 正在使这个 div .signature 在页面上 100% 宽。需要将 div 两边的边距相等。 Margin 是说在顶部和底部放置 0px 边距,在左右两侧放置 autoPosition 使其固定在视口/页面上。 Bottom 表示将 0px 从底部保留。

    在页面正文中,使用以下代码:

    <?php
        foreach ($orders as $order) {
            ?>
            //<div class="order">order1 go here </div>
            //<div class="order">order2 go here </div>
            //<div class="order">order3 go here </div>
            //<div class="order">order4 go here </div>
            <?php
        } // for each ENDS
    ?>
    
    <div class="signature">
          Authorized by <?php echo $who_authorized; ?> |
          Printed by <?php echo $who_printed; ?>
    </div><!--//signature-->
    

    它只是将您在 CSS 样式中定义的任何属性分配给 signature div。显然,您需要将此 sn-p 包装到您的逻辑中,该逻辑决定何时回显/引入 signature div。此外,$who_authorized 和 $who_printed 需要保持一些价值。

    对于任何大于 3 行的块,我总是使用 PHP 解析器/控件 (?&gt;) 并根据需要简单地编写 HTML。然后,当需要时,我再次输入 PHP (&lt;?php)

    如果你想使用 include,你可以省略最后 6 行(从我的代码中以 ?&gt; 开始 & 以 &lt;!--//signature--&gt; 结尾,只需将这一行放在那里。

    include ("footer.php");
    ?>
    

    此选项还要求您在同一目录中创建一个名为footer.php 的文件,并在其中插入以下html代码。

    <div class="signature">
          Authorized by <?php echo $who_authorized; ?> |
          Printed by <?php echo $who_printed; ?>
    </div><!--//signature-->
    

    【讨论】:

    • 我需要如何格式化footer.php中的代码以使其显示在打印页面的底部?
    • 你在这里给我的方法并没有完全按照我的需要去做。我可以让它重复每张发票的页脚,但我无法让它出现在页面底部。我想我可以作弊并用空格填充它。
    • @Bagellord 你能在你的问题中发布一些相关的代码吗?然后我们就可以找出问题所在了。
    • 我会在早上回到办公室时。
    • &lt;style type="text/css"&gt; .picklistCheck{ width:15px; height:15px; border:1px solid #c7c7c7; margin:0 auto; border-radius:2px; box-shadow:inset 0px 0px 2px rgba(0,0,0,0.1); font-size:14pt; } .signature{ border-bottom-style:solid; font-size:14pt; page-break-after:always; } td{ font-size:14pt; } &lt;/style&gt; &lt;?php foreach ($orders as $order) { ?&gt; //orders go here &lt;/div&gt; &lt;!--&lt;?php include ("footer.php"); ?&gt;--&gt; &lt;?php } ?&gt;
    【解决方案2】:

    您的发票采用什么格式?您应该将它们创建为 PDF 文件以将它们打印出来。在那里你可以尝试定义一个脚注 - 基于使用的 php pdf 库

    【讨论】:

    • PDF 对于我们的目的不是必需的。但无论如何,格式是顶部的客户信息,然后是行项目(订购的商品),然后是总数,然后是空格。我需要在每张发票的底部为谁打印和授权发票放置一个签名行。发票也很容易超过 1 页。
    【解决方案3】:

    创建一个footer.php 文件,其中包含要放置在页脚中的html。

    将此代码放置在发票页上要放置页脚的位置:

    <?php include 'footer.php'?>
    

    要修改页脚,修改footer.php

    【讨论】:

    • 如果这有帮助,您将成为我在互联网上的新宠。我会对其进行测试并报告。
    • 不要使用短代码。使用: 确保您的代码尽可能面向未来。编辑:阅读完整的问题后,这甚至都行不通。此解决方案会将页脚放在网页的末尾,而不是每个打印页面的末尾。
    猜你喜欢
    • 2012-12-29
    • 2012-03-08
    • 2012-01-11
    • 1970-01-01
    • 2013-12-01
    • 2017-10-22
    • 1970-01-01
    • 2015-03-11
    • 2017-10-11
    相关资源
    最近更新 更多