How to give margin left to table in itextsharp

ankit sharma picture ankit sharma · Oct 14, 2015 · Viewed 16.3k times · Source

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

Answer

rhens picture rhens · Oct 15, 2015

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