ankit sharma
ankit sharma

Reputation: 449

How to give margin left to table in itextsharp

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

Upvotes: 10

Views: 21286

Answers (2)

rhens
rhens

Reputation: 4871

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);

Upvotes: 17

ankit sharma
ankit sharma

Reputation: 449

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();
    }
}

Upvotes: -1

Related Questions