ITextSharp Margin

I am working with itexsharp and I have problem because it does not assign the margin of the document This is the code.

Dim pdfw As PdfWriter
    Dim documentoPDF As New Document(iTextSharp.text.PageSize.A4.Rotate(), 20, 20, 20, 20) 'Creamos el objeto documento PDF
    documentoPDF.SetMargins(0.0F, 0.0F, 10.0F, 10.0F)

    pdfw = PdfWriter.GetInstance(documentoPDF, New FileStream(urlFija & "\" & "Manifiesto-" & Manifiesto & ".pdf", FileMode.Create))
    documentoPDF.Open()


    documentoPDF.NewPage()
    Dim aTable = New iTextSharp.text.pdf.PdfPTable(3)
    Dim Ancho0 As Single() = {0.75F, 1.45F, 0.75F}
    'aTable.DefaultCell.Border = BorderStyle.None

    Dim Imagen As iTextSharp.text.Image
    Imagen = iTextSharp.text.Image.GetInstance(path & "Ministerio-3.jpg")
    Imagen.ScalePercent(25)
    Imagen.SetAbsolutePosition(25.0F, 25.0F)

    Dim Img = New PdfPCell
    Img.Border = Rectangle.NO_BORDER
    Img.AddElement(Imagen)

    aTable.AddCell(Img)

    Dim C1 = New PdfPCell(New Paragraph("Formato", FontFactory.GetFont(FontFactory.TIMES, 13, iTextSharp.text.Font.BOLD)))
    C1.HorizontalAlignment = 1
    C1.VerticalAlignment = 2
    C1.Border = Rectangle.NO_BORDER

    aTable.AddCell(C1)

    Dim C2 = New PdfPCell(New Paragraph("Prueba", FontFactory.GetFont(FontFactory.TIMES, 7, iTextSharp.text.Font.NORMAL)))
    C2.HorizontalAlignment = 3
    C2.Border = Rectangle.NO_BORDER
    aTable.AddCell(C2)
    aTable.SetWidths(Ancho0)
documentoPDF.Add(aTable)
documentoPDF.AddAuthor(Session("IDUsuario").ToString)
    documentoPDF.AddTitle("Manifiesto")
    documentoPDF.AddCreationDate()
    documentoPDF.Close() 

After this I added a table with the information, move me just the top margin

Upvotes: 0

Views: 1907

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

As documented, the width of a PdfPTable takes only 80% of the available width by default when you add it to a page (unless you define an absolute width instead of a relative width). It will be centered, so you will have a left and a right margin of 10% of the available width.

If you want the table to span 100%, you need to add this line:

aTable.WidthPercentage = 100;

Now the table will span the full width.

Upvotes: 2

Related Questions