Domanda

I'm trying to find something like \vfill from Latex in iTextSharp (a way to insert spaces and place text at the bottom of the page). It's only for one page, not a footer.

I searched online and in the book iText in Action, but didn't find any answers.

È stato utile?

Soluzione

OK, after a long time and trying many things, I have found a solution.

Some things I tried that "worked", but not good enough:

First I calculated the height of my paragraph (by writing it in a new table in a new document in the RAM), then I would add newlines until there was just enough room for my text. Result: NOT a good way, the text would by off by a few points (the y position in the document, because of the newlines).

Then I tried to do this with ColumnText: too many calculations (since my document is dynamic) and I didn't like positioning it absolute.

So my solution is to use a PdfPTable:

            var t = new PdfPTable(1);
            t.ExtendLastRow = true;
            t.WidthPercentage = 100; 

            var c = new PdfPCell();
            c.VerticalAlignment = Element.ALIGN_BOTTOM;
            c.DisableBorderSide(Rectangle.BOX);

            var p = new Paragraph("This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.");
            p.Alignment = Element.ALIGN_JUSTIFIED;

            c.AddElement(p);

            t.AddCell(c);

            doc.Add(t);

Pretty simple, but I lost a lot of time on this. I hope this helps others too.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top