Giri Giri - 1 year ago 171
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;

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.SetSimpleColumn(100, 100, 500, 500);

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;

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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download