using System; using System.Collections.Generic; using System.Text; using System.IO; using iTextSharp.text.pdf; using iTextSharp.text; namespace iTextSharpTests { class Program { static void Main(string[] args) { // step 1: creation of a document-object Document document = new Document(PageSize.LETTER, 50, 50, 50, 50); // step 2: creation of the writer File.Delete("test.pdf"); PdfWriter writer = PdfWriter.GetInstance(document, File.OpenWrite("test.pdf")); writer.PageEvent = new TestEvent(); // step 3: we open the document document.Open(); // step 4: we add content to the document PdfContentByte cb = writer.DirectContent; ColumnText ct = new ColumnText(cb); ct.SetSimpleColumn(document.Left, document.Bottom, 300f, document.Top); Paragraph p =new Paragraph(float.NaN, ""); p.SetAlignment("left"); p.Add(new Chunk("This is some lame text. This is some lame text. This is some lame text. This is some lame text. This is some lame text. This is some lame text. This is some lame text. This is some lame text. This is some lame text. This is some lame text.")); Chunk hr = new Chunk(" "); hr.SetGenericTag("hr"); PdfPTable t = new PdfPTable(new float[] { 50f, 50f}); t.WidthPercentage = 100f; t.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE; t.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; t.DefaultCell.Border = 0; t.DefaultCell.BorderWidth = 0; t.AddCell(p); t.AddCell(p); t.AddCell(new Paragraph(hr)); // there should be a line here spanning the cell t.AddCell(p); ct.AddElement(t); ct.Go(); // step 5: we close the document document.Close(); } } public class TestEvent : PdfPageEventHelper { public TestEvent() {} public override void OnGenericTag(PdfWriter writer, Document document, Rectangle rect, string text) { float x1 = rect.Left; float x2 = rect.Right; float y = rect.Top - ((rect.Top - rect.Bottom) / 2); writer.DirectContent.SetLineWidth(1f); writer.DirectContent.SetColorStroke(Color.BLACK); writer.DirectContent.MoveTo(x1, y); writer.DirectContent.LineTo(x2, y); writer.DirectContent.Stroke(); writer.DirectContent.ResetRGBColorStroke(); } } }