Nilabhra Banerjee wrote:
> You are right in assuming I have to set a new Customer String for every
> Customer. The problem is
> a) For each customer there may be more than two or three pages (just
> like Endpage example)
OK, that's a requirement, not a problem ;-)
> b) And every new customer record should begin at new page. (that's why
> document.newPage.)
No Problem. That makes sense.
> To identify which customer details to use (from an ArrayList) for the
> header I thought I could use count as the customer number. But this
> count won't match with the page number (it will be always less).
I understand. You will have something like this:
p1: customer 1
p2: customer 1
p3: customer 1
p4: customer 2
p5: customer 2
p6: customer 3
and so on...
Still no problem.
> That is why I felt there needs to be a synchronization between printing
> and OnEndPage event.
Oops: problem! I don't understand the above sentence.
> You have suggested the use of member variable but
> which customer it is to be printed as header in current page that I must
> know. That I can get only from the count .
No... I still don't understand what you mean.
> I have also gone through the slideshow link you have provided and I
> understand the pdfwriter can be used to exchange info.
>
> If there is any option like Pdfwriter.setPageNumber(int) and
> Pdfwriter.getPageNumber(), I can add the count in the pagenumber (for
> each count add 100, then get the pagenumber at OnEndPage event and
> divide by 100 to get count).
Now you have completely lost me.
Why don't you do this in a more simple way.
Here's some PSEUDOCODE showing how I would do it.
MyEventClass extends PdfPageEventHelper {
int pagenumber;
String customerid = "";
public void setCustomerInfo(String customerid) {
pagenumber = 0;
this.customerid = customerid;
}
public void onEndPage(...) {
pagenumber++;
// draw your header and footer using pagenumber and customerid
// but in a simpler way than in your initial code sample
...
}
}
MyMainClass {
public static void main(String[] args) {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(...);
MyEventClass event = new MyEventClass();
writer.setPageEvent(event);
document.open();
List list = getCustomerIds();
String id;
for (Iterator i = list.iterator(); i.hasNext(); ) {
id = (String) i.next();
event.setCustomerInfo(id);
document.newPage();
// add as many pages you want
}
}
public static List getCustomerIds() {
List list = new ArrayList();
// fill the list with Strings
...
return list;
}
}
There may or may not be a small problem with the header/footer
on the first page, but it's nothing you won't be able to fix.
br,
Bruno
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions