简体   繁体   English

如何使用iTextSharp在pdf中将段落绝对定位?

[英]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. 我正在使用ASP.NET,C#和iTextSharp从头开始动态创建pdf。

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. 因此,如您所知,我想到了使用paragraph.spacebefore。 But i need to position three paragraph in pdf and i am getting the text for the paragraphs from the user. 但是我需要在pdf中放置三个段落,并且我要从用户那里获取段落的文本。 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? 可能吗?

I found the answer it is simple. 我发现答案很简单。 We can set the columntext property. 我们可以设置columntext属性。

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. 因此,如果将columntext用于段落的绝对位置,则段落属性将不起作用。 But we can use the columntext property. 但是我们可以使用columntext属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM