10

I am using these code ...my tables are sticked to left side of document as i havent given any paddings in document...

Document document = new Document(PageSize.A4, 0, 0, 0, 0);

But now i want to give margin left and margin right to my tables ...i used

outerTable.SpacingBefore = 20f;

it did n't work then i tried to give padding left to my cell it didnt work too..

outerCell.PaddingLeft = 20f;

Now my tables are sticked to left sides..how would i move them? Help if you have done trying moving tables in itextsharp...

pls check attached screen for reference

enter image description here

ankit sharma
  • 449
  • 1
  • 6
  • 17

2 Answers2

17

The easiest way to get a table with a "left margin" is probably to wrap the table in a paragraph and set a left indentation on that paragraph

Paragraph p = new Paragraph();
p.IndentationLeft = 100;
outerTable.HorizontalAlignment = Element.ALIGN_LEFT;
p.Add(outerTable);
document.Add(p);
rhens
  • 4,791
  • 3
  • 22
  • 38
-1

I was trying to move table from document.left position but it didnt work then i tried to give padding in cell that even dont work too....

Then i changed in RoundRectangle class

where i changed **rect.Left + 40f,** this line in RoundRectangle() function and it worked for me.......

public class RoundedBorderLeft : IPdfPCellEvent
{
    public void CellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas)
    {
        PdfContentByte cb = canvas[PdfPTable.BACKGROUNDCANVAS];
        cb.SetRGBColorStroke(42, 177, 195);
        cb.RoundRectangle(
         **rect.Left + 40f,**
         rect.Bottom + 1.5f,
        rect.Width - 20,
        rect.Height - 3, 4
         );

        cb.Stroke();
    }
}
ankit sharma
  • 449
  • 1
  • 6
  • 17
  • `CellLayout` is called after a cell has been placed on the page, to allow you to still do some operations like painting a border or coloring the background. The position is already determined: the `Rectangle` that is passed contains the coordinates. So you can't tweak the margins this way. Maybe your offset on the left border will give the visual impression of a left margin, but be careful with the cell content. If the cell content grows, you might paint you left border through the content. – rhens Oct 15 '15 at 11:55