问题
I am working on an ordering system for my company utilizing Open Cart.
Everything is being done in PHP and HTML.
I am trying to modify the invoice page to include a signature line at the bottom of the printed invoice. Invoices can stretch to multiple pages depending on the number of lines/items, and they can also be batched so that one document to be printed has multiple invoices (using a loop). I am not a web developer, and have hit the end of my abilities to get this part of the project done. Please give me pointers or pseudo code samples.
Footer Code:
<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");
?>
回答1:
Every time your logic decides to put a page break in the invoice, tell it to insert the following code also:
<?php include ("footer.php"); ?>
Create a footer.php file with the simple html you want to place in the footer. The above code assumes that your script
and footer.php
are in same directory.
EDIT: To answer your comment,
The Include PHP.net will behave exactly like you actually copy-pasted all the code directly instead of including it. But every include file should have its own <?php ?>
tags where-ever required. Without <?php ?>
tags, Control will just output whatever it sees there.
Footer.php can be a simple HTML-only file:
<div id="footer">
Company XYZ (c)2000-2012 All Copyrights Reserved
Some other footer text.
</div>
You could also name it footer.html, but if later, in future, you decide to put some dynamic data in footer, it will be very difficult to change .html
to .php
in all include lines written in various files.
Example of Dynamic Footer:
<div id="footer">
Company XYZ (c)2000-2012 All Copyrights Reserved
<?php echo $who_printed." ".$who_authorized; ?>
</div>
Of course it is just a simple example.
In a html page, you could force a div by using the following CSS code in an external linked .css file:
#footer{
text-align: right;
height: 20px;
position:fixed;
margin:0px;
bottom:0px;
}
position:fixed;
& bottom:0px;
is here doing the trick. It is forcing this "footer" div
to stick to bottom always, even if page is scrolled or something. Like the way Facebook sticks its header menu to top & chat bar to bottom. You can also define left, right properties
Update: Ok, based on your comments, here is the sample code:
In CSS Style section, use:
.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;
}
All properties are self-explanatory. Text-align
makes the text center-aligned. Width
is making this div .signature
100% wide on page. It is required to put the div with equal margins on both sides. Margin
is saying put 0px
margin on top & bottom sides and auto
on both left & right side. Position
makes it fixed on viewport/page. Bottom
says keep 0px
from bottom.
In body of page, use this code:
<?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-->
It simply assigns whatever properties you defined in CSS Styling to signature
div. Obviously you need to wrap this snippet into your logic, which decides when to echo/introduce the signature
div. Also, $who_authorized & $who_printed needs to hold some value.
For any block bigger than 3 lines, I always come out (?>
) of PHP parser/control and simply write HTML as desired. Then, when required, I again enter PHP (<?php
)
If you want to go with include
, you can omit the last 6 lines( starting from ?>
& ending with <!--//signature-->
from my code and simply put this line there.
include ("footer.php");
?>
This option also requires you to create a file named footer.php
in the same directory and insert the following html code in it.
<div class="signature">
Authorized by <?php echo $who_authorized; ?> |
Printed by <?php echo $who_printed; ?>
</div><!--//signature-->
回答2:
What format do your invoices have? You should create them as a PDF File to print them out. There you can try to define a footnote - based on the used php pdf library
回答3:
Create a footer.php file with the html you want to place in the footer.
Place this code where you want the footer to be placed on the invoice page:
<?php include 'footer.php'?>
To modify the footer, modify footer.php
来源:https://stackoverflow.com/questions/11396322/how-to-print-footer-on-each-printed-page