Hi,

I'm having problems to determine the top margin with room for the header, when this header was written onEndPage event.
I couldn't found a way of calculating this margin.

I have a method for producing the document that looks like this:

            if(this.config.getLandscape()){
                this.document=new Document(PageSize.A4.rotate());
            }else{
                this.document=new Document(PageSize.A4);
            }
            PdfWriter writer=PdfWriter.getInstance(this.document, out);
            writer.setPageEvent(new PDFDefaultHeaderAndFooter(config, columns, cols));
               // here I fix top margin because I don't know how to calculate it.
            this.document.setMargins(20f, 20f, 200f, 20f);
            this.document.open();
            int headerCount=0;
            for(PdfPTable table : this.tables){
                if(this.hasGroups && headerCount<this.headerGroups.size()){
                    this.document.add(this.headerGroups.get(headerCount));
                    headerCount++;
                }
                this.document.add(table);
            }
            this.document.close();

In this case the PDFDefaultHeaderAndFooter class is responsible for actually write the header, and it also calculate the Y pos where it ends.
The method in this class looks like:

    @Override
    public void onEndPage(PdfWriter writer, Document document) {
        float width=document.right()-document.left();
       
        PdfPTable header=this.buildHeader(writer.getPageNumber());
        header.setTotalWidth(width);
        float y;
        if(!config.getLandscape())
            y=header.writeSelectedRows(0, -1, document.left(), 806, writer.getDirectContent());
        else
            y=header.writeSelectedRows(0, -1, document.left(), 566, writer.getDirectContent());
        header=this.buildFilterHeader();
        if(header!=null){
            header.setTotalWidth(width);
            y=header.writeSelectedRows(0, -1, document.left(), y, writer.getDirectContent());
        }
        header=this.buildColumnTitles();
        header.setTotalWidth(width);
        y=header.writeSelectedRows(0, -1, document.left(), y, writer.getDirectContent());
        this.headerYEnd=y;
    }
This method writes many headers, some of the are variable in height depending on data.
So I have the data in headerYEnd on this class.
The question is: how can I set the top margin as a function of the calculated headerYEnd value?
Or how can I calculate the resulting headerYEnd before in order to set top margin?

Waiting for your comments.
Thank you in advance.
Daniel



------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to