Alternative for LineSeparator in iText old versions?

Viewed 48908

I'm trying to insert a line separator (you know, that horizontal line that runs across documents) into my document with iText. I've found some resources via Google that use com.lowagie.text.pdf.draw.LineSeparator but the version of iText that I'm using (1.4.2) doesn't seem to have that package.

Can anyone suggest another way to add a nice line seperator for my pdf? And please don't say update the .jar-- I'm locked in to 1.4.2.

Thanks!

9 Answers

The solution given by Sean offer more flexibility when dealing with a text underlined by the line separator. I don't know if LineSeparator can do that, it seems to be meant to be just a line separator.

Paragraph ph = new Paragraph(new Phrase("My line separator", yourFont));
PdfPCell cell = new PdfPCell(ph);
cell.Border = Rectangle.BOTTOM_BORDER;
cell.BorderColor = new BaseColor(44, 67, 144);
cell.BorderWidth = 2f;

PdfPTable table = new PdfPTable(1);                
table.AddCell(cell);
table.HorizontalAlignment = Element.ALIGN_LEFT;
table.WidthPercentage = 100f;
doc.Add(table);

Hope this can help. Should print something like this .A line separator with text

Related