Nico Van den Broeck wrote:
Bruno,
Let me try to explain the whole picture.
At this moment a servlet is generating PDF files (offers, orders, invoices
...) from a database to the browser.
The user passes a few parameters to the servlet (type of doc, id, requested
version ...), the servlet searches the necessary data in the database,
composes the document and returns it to the browser.
All my documents have a dynamic header and footer (PdfPTables which contains
data also coming out of the database) which are added via page events.
This combination is working fine but the only limitation at this time is
that I can only put one invoice in a PDF and return it to the browser.
The problem I'm heaving is that different versions of an invoice exists
(client version, internal version, accountancy version ...) each version
heaving it's own (dynamic) header and footer added via page events.
Sometimes a list of documents (different id's) of the same version (i.e.
client version) is requested.
For those kinds of request I want to return one PDF to the browser
containing different invoices, each invoice heaving its own (different from
the others) header and footer added via page events.
Until now I was not using page events and I could easily add one table for
each invoice version and begin a new page in to separate them.
I used table.setHeaderRows(x) to implement the header.
For the footer I used a PdfPTable which I added at the end of the document.
PdfPTable footer=new PdfPTable(table_widths_1);
...
footer.writeSelectedRows(0, -1, 18, 100, writer.getDirectContent());
The disadvantage of this footer is that it only appears on the last page of
each invoice version and that the total number of pages is missing. That's
why I'm using page events now.
The first question I would like to ask is what would be the best approach to
merge/concat different invoice versions to one PDF document?
I've already searched the mailing list several times making test models over
and over again (for 4 weeks now). None of them is giving a successful
result.
One of your suggestions I found was to use byte[] to merge PDF's in memory.
I'm not a java expert and I cannot tell if this is the best approach for my
problem.
What do you see as possible solutions?
For performance reasons, I wouldn't create different files and
concatenate them afterwards. Instead I would define a PageEvent that
keeps the header and footer
table in a membervariable.
I would do something like this (this is psuedo code!):
Event event = new Event()
writer.setEvent(event);
for (loop over invoices) {
header_invoice[i] = new PdfPTable();
footer_invoice[i] = new PdfPTable();
event.setHeaderTable(header_invoice[i]);
event.setFooterTable(footer_invoice[i]);
document.add(invoice_data);
document.newPage();
}
Do you get the idea?
Before adding the invoice data, you change the header and footer table
in the event. You add data to the document and in the onEndPage method
of the Event, the current header and footer are added.
When the current invoice is done, you invoke a new page, change the
header and footer and continue.
That way you don't have to worry about concatenating different files.
Although concatenating PDFs that are passed as byte[] must work.
I really don't know what goes wrong in your code.
br,
Bruno
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions