How to make the pagination of an invoice
Some ago days a project arrived of most interesting: the proprietor of a Web with sale online managed the invoices from the same webpage and had the problem of which at the time of printing the invoices well they were not paginated.
As lover of algorithmic that always I have been since I discovered this discipline in first of race this project was to me a very attractive challenge.
An invoice is formed by a head, the lines of detail of the invoice and I cheeped of invoice.
When a printed invoice occupies several pages, each one of the pages must contain the head, the number of page that is and the total number of pages. Only the last one of the pages will have to contain I cheeped of invoice.
If we showed an invoice in a webpage is well if is the head, the lines and soon I cheeped, but at the time of printing it is going to us to occupy more than a page we will have to satisfy the requirement to repeat the heads.
In my case I had to realise the modifications in PHP, but I write the algorithm in pseudocode so that he is understandable for all the programmers.
We are going to consider that before putting to show the invoice to us by screen we are going to have in variables the data of head, the data of the invoice foot and an Array with the lines of detail of the invoice.
fin_lineas_factura = false pagina_actual = 0 linea_actual = 0 total_lineas = so large (lineas_factura) altura_hoja = 28 while (not (fin_lineas_factura)) to do altura_informacion = 0 pagina_actual = pagina_actual + 1 to write: cabecera_factura () altura_informacion = altura_informacion + 3 to write: pagina_actual page altura_informacion = altura_informacion + 1 to write: mostrar_inicio_tabla_detalles_factura (code, concept, matter, discount, etc.) while ((linea_actual < total_lineas) and (altura_informacion < altura_hoja) to do to write: linea_actual lineas_factura  altura_informacion = altura_informacion + 1 linea_actual = linea_actual + 1 aim while if (linea_actual = total_lineas) to do fin_lineas_factura = certain to write: pie_factura () if not to do pagina_actual = pagina_actual + 1 to write: it continues by the p¡gina_actual page salto_de_pagina* aim if aim while
In order to make the form feed it is necessary to use some strangers properties CSS2:
<div style= " page-break-after: always; ; > </div>
I hope that it is to you of utility.