I'm using iText 5.3.5 to create a pdf document. Right now I am trying to get a rectangle on every single page of the document but I'm not pretty sure of how to do this. I tried adding this at the end of my code (I found it on the internet):
PdfContentByte cb = writer.getDirectContent();
for (int pgCnt = 1; pgCnt <= writer.getPageNumber(); pgCnt++) {
cb.saveState();
cb.setColorStroke(new CMYKColor(1f, 0f, 0f, 0f));
cb.setColorFill(new CMYKColor(1f, 0f, 0f, 0f));
cb.rectangle(20,10,10,820);
cb.fill();
cb.restoreState();
}
but this only adds the rectangle on the last page and it kind of make sense because I'm not using the pgCnt anywhere. How can I specify that I want the rectangle on page number pgCnt, so I can add the rectangle on every page?
Hope I explained myself. Thanks in advance for your help. :)
PdfStamper
editing an already existing PDF while you added it to code using aPdfWriter
creating a new PDF. In that case the sample code should be used not merely once but instead (by means of a page event listener) once per page.