itextsharp: how do i position a table?

itext, vb.net, winforms

Solution

You can do something like this:

PdfPTable foot = new PdfPTable(2);
foot.TotalWidth = page.Width - document.LeftMargin - document.RightMargin;
foot.WriteSelectedRows(0, -1, document.LeftMargin, document.BottomMargin,
                       writer.DirectContent);

Problem

I have created a simple table and i need to position. does anyone have experience with tables in itextsharp? here's my code ``` Private Sub generate_PDF() Directory.SetCurrentDirectory("C:\Users\alexluvsdanielle\Desktop\") Console.WriteLine("Chapter 6 example 1: Adding a Wmf, Gif, Jpeg and Png-file using urls") Dim document As Document = New Document Try Dim writer As PdfWriter = PdfWriter.GetInstance(document, New FileStream("Chap1002.pdf", FileMode.Create)) document.Open() 'Dim wmf As Image = Image.GetInstance("harbour.wmf") 'Dim gif As Image = Image.GetInstance("vonnegut.gif") Dim jpeg As Image = Image.GetInstance("C:\Users\alexluvsdanielle\Desktop\test.jpg") 'Dim png As Image = Image.GetInstance("hitchcock.png") 'document.Add(wmf) 'document.Add(gif) jpeg.ScalePercent(50) 'jpeg.Alignment = Image.TOP_BORDER jpeg.SetAbsolutePosition(0, 562) document.Add(jpeg) 'document.Add(png) Dim cb As PdfContentByte = writer.DirectContent cb.BeginText() Dim bf As BaseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED) cb.SetFontAndSize(bf, 12) 'Dim text As String = "Sample text for alignment" 'cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, text + " Center", 250, 700, 0) 'cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, text + " Right", 250, 650, 0) 'cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text + " Left", 250, 600, 0) cb.SetTextMatrix(150, 652) cb.ShowText(patient_name) cb.SetTextMatrix(150, 637) cb.ShowText(doc_name) cb.SetFontAndSize(bf, 8) cb.SetTextMatrix(150, 620) cb.ShowText(lot__no) cb.SetTextMatrix(150, 611) cb.ShowText(patient_id) Dim i As Integer For i = 1 To 10 cb.SetTextMatrix(150, 600 - (i * 10)) cb.ShowText(DataGridView1.Item(3, i).Value) Next cb.EndText() Dim aTable As Table = New Table(2, 2) aTable.Offset = 10 aTable.Width = 100 aTable.AddCell("0.0") aTable.AddCell("0.1") aTable.AddCell("1.0") aTable.AddCell("1.1") document.Add(aTable) Dim datatable As PdfPTable = New PdfPTable(12) Dim page As Rectangle = document.PageSize datatable.TotalWidth = 100 datatable.AddCell("hello") datatable.WriteSelectedRows(0, -1, document.LeftMargin, document.BottomMargin, writer.DirectContent) document.Add(datatable) Catch de As DocumentException Console.Error.WriteLine(de.Message) MessageBox.Show(de.Message) Catch ioe As IOException Console.Error.WriteLine(ioe.Message) MessageBox.Show(ioe.Message) Catch e As Exception Console.Error.WriteLine(e.Message) MessageBox.Show(e.Message) End Try document.Close() End Sub ``` the first table works but the second does not

Original source