Giri Giri - 19 days ago 7
C# Question

How to absolute position the paragraph in pdf using iTextSharp?

I am using ASP.NET,C# and iTextSharp for creating the pdf dynamically from scratch.

I am using this.

Phrase ph = new Phrase(text);
Paragraph p = new Paragraph(ph);
p.Alignment = Element.ALIGN_JUSTIFIED;
p.SpacingBefore = spaceBefore;
p.FirstLineIndent = 170;
p.IndentationLeft = 30;
p.IndentationRight = 50;
doc.Add(p)


So as you know i thought of using paragraph.spacebefore. But i need to position three paragraph in pdf and i am getting the text for the paragraphs from the user. So now based on the number of lines of the previous paragraph the next paragraph will vary with height that i don't want.

Then i thought of using this.

ColumnText ct = new ColumnText(cb);
ct.AddText(p);
ct.SetSimpleColumn(100, 100, 500, 500);
ct.Go();


But in this case i want the starting point of first and second line to be different, like this

p.FirstLineIndent = 170;
p.IndentationLeft = 30;
p.IndentationRight = 50;


Edit:
When i try this,the properties are does not affect these paragraphs just all the lines are starting from the same point.

Is it possible?

Answer

I found the answer it is simple. We can set the columntext property.

columntext.SetIndent(100, false);

It will add the space to only firstline.Then for linespacing I used this.

columntext.Leading = 31;

So if use the columntext for absolute position of paragraph then the paragraph property wont work. But we can use the columntext property.