简体   繁体   English

如何在iText7中填充行的剩余空间

[英]How to fill remaining space of a line in iText7

I'm trying to fill the remaining space of the last line of a paragraph using iText7 with C#: 我正在尝试使用带有C#的iText7填充段落最后一行的剩余空间:

var par = new Paragraph(text);
par.Add(c);
document.Add(par);

How can i add - char to fill the space left by the line? 我如何添加-焦填补行留下的空间? Something like LineSeparator(new DashedLine() but from the beginning on the last character of my paragraph instead of new line. 类似于LineSeparator(new DashedLine()但从我段落的最后一个字符开始,而不是换行。

You can use the concept of tabs and tab stops for it. 您可以使用制表符和制表位的概念。 This concept is not iText-specific. 此概念不是特定于iText的。 Roughly speaking you can define points (tab stops) and adding a tab would "jump" to the next point. 粗略地说,您可以定义点(制表位),添加制表符将“跳转”到下一个点。 In your case the tab stop is the end of the line and you only need one tab. 在您的情况下,制表位是行的结尾,您只需要一个制表符。

Here is a complete example that uses small dashes on the baseline as the filling. 这是一个完整的示例,使用基线上的小破折号作为填充。 You can implement ILineDrawer yourself to customize the behavior or subclass/configure an existing implementation. 您可以自己实现ILineDrawer以自定义行为或子类化/配置现有实现。 The code is in Java, but to convert it to C# you basically need to do some capitalization and that's it. 该代码使用Java,但是要将其转换为C#,您基本上需要进行大写,仅此而已。

Document doc = ....;
Paragraph p = new Paragraph("Hello world").add(new Tab());
ILineDrawer filling = new DashedLine();
PageSize pageSize = doc.getPdfDocument().getDefaultPageSize();
Rectangle effectivePageSize = doc.getPageEffectiveArea(pageSize);
float rightTabStopPoint = effectivePageSize.getWidth();
TabStop tabStop = new TabStop(rightTabStopPoint, TabAlignment.LEFT, filling);
p.addTabStops(tabStop);
doc.add(p); 

Result looks as follows: 结果如下:

结果

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

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