0

We're working on a shopping cart-like program in Java. One of the requirements is that the receipt sent to the users will be a pdf file, and it could be composed of multiple pages, so pagination is required. We're using iText to create the pdf, and HTML to create the layout of the receipt.

I know that I can add the footer using PageEvents and adding the footer HTML on the onEndPage() method.

I was wondering if there is a way to add pagination to the footer html text of the receipt that our users will receive. (Page 1 of n, Page 2 of n, ... Page n of n).

Note though. Users can also edit the footer of the receipts they can receive, so they can rearrange the content of the end of the page.

For example:

Customer A's footer for his receipt may go:

<div class="left-footer companyLogo">...</div>
<div class="center-footer pagination">PAGINATION</div>
<div class="right-footer companyName">...</div>

While Customer B's footer may go:

<div class="left-footer Disclaimer">...</div> 
<br/>
<div class="left-footer pagination">PAGINATION</div>
<div class="right-footer date-footer">$dateToday</div> 

And then the $variableName would be parsed by a custom template parser

mkl
  • 90,588
  • 15
  • 125
  • 265
  • Possible duplicate of [Pagination in ItextPdf](http://stackoverflow.com/questions/28333204/pagination-in-itextpdf) – Amedee Van Gasse Mar 08 '16 at 07:28
  • Yes, it is possible. @AmedeeVanGasse's reference shows how it can be done in general. But somehow you seem to want to describe that your situation is not that of the referenced answer. In that case, please illustrate. A short code sample can sometimes help a lot... – mkl Mar 08 '16 at 07:44
  • Not sure if this is more clear, but I added some possible html code for the footers. But as I said, a customer may want to customize it even more, even remove the pagination. But for those who want pagination, I'm not sure how to deal with that anymore. – Abraham Miguel Espiritu Mar 08 '16 at 08:17
  • @AbrahamMiguelEspiritu Ok, so the first thing you have to do is which variables you want to support, in particular which variables with a non-trivial behavior (PAGINATION is non-trivial because it depends on the current state of the PDF creation while $dateToday is trivial as it can be determined once and then be assumed fixed). Is PAGINATION the only non-trivial one? – mkl Mar 08 '16 at 16:08
  • @mkl Yes, Pagination is the only non-trivial one. The other variables will be fetched from the database, so we can insert them easily. – Abraham Miguel Espiritu Mar 09 '16 at 05:34
  • Ok, then it should be possible to use the `onEndPage` HTML output using `XMLWorker`. As far as I know, though, you will need to implement a custom tag which inserts a template into which at the end of document processing the total number of pages in the document is written. I'm not that deep into `XMLWorker` usage, so probably someone else can give more detailed hints? – mkl Mar 09 '16 at 10:57
  • I changed the tags from [tag:pagination] to [tag:page-numbering] as your issue is not the distribution of content onto multiple pages but the adding of page numbers and page number totals. – mkl Mar 09 '16 at 11:01

0 Answers0