How can I use CSS properties such as padding, cell-spacing, background color, etc... in iTextSharp?
Asked
Active
Viewed 1,145 times
2 Answers
0
You can Use PdfPTable
PdfPTable headerTbl = new PdfPTable(2); //Create table with 2 Cols
headerTbl.SetWidths(new float[] { 4, 1 }); //1st having size of 4 and other 1
headerTbl.TotalWidth = doc.PageSize.Width; //Total Width of the table
headerTbl.SpacingBefore = 20f;
headerTbl.SpacingAfter = 30f;
You can Create Cells inside PdfPTable
Using this
PdfPCell cell = new PdfPCell
cell.Colspan = 3; //Colspan
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right Horizontal alignment
References

Dgan
- 10,077
- 1
- 29
- 51
0
There are plenty of Java examples available that explain how to use XML Worker and CSS: http://itextpdf.com/sandbox/xmlworker
Some of these examples were written in answer to StackOverflow questions about iTextSharp:
- How to get particular html table contents to write it in pdf using itext (See ParseHtmlTable1 and ParseHtmlTable2 for a table with padding defined for
th
andtd
tags.) - Element inside class CSS definition not applied using ITextSharp (5.5.1) XHTML to PDF (See ParseHtmlTable3 for an example where we define a green border in CSS.)
- RowSpan does not work in iTextSharp? (See ParseHtmlTable4 for an example where we define a rowspan and a colspan, including a background color for cells.)
- how can I add cellspacing to pdftable when parsing html using XMLWorker and itext (See ParseHtmlTable5 for an example where we use CSS to define a border-spacing and a padding.)
In a way, your question is not eligible for StackOverflow because it is too broad (you don't show what you've tried) and it is a duplicate of other questions.
Please make sure that you consult the official documentation, as well StackOverflow questions that have been answered (and accepted) in the past before creating a new question.

Community
- 1
- 1

Bruno Lowagie
- 75,994
- 9
- 109
- 165
-
I want to use Margin , padding , position of a text – user2115472 Nov 10 '14 at 17:03