vb.net 如何在itextsharp中的段落下放置下划线

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25864159/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:13:30  来源:igfitidea点击:

How to place underline under a paragraph in itextsharp

asp.netvb.netitextsharp

提问by bhagirathi

I am using iTextSharp in my current project. I have created a table with some underlined data but my requirement is shown in this image:

我在当前项目中使用 iTextSharp。我创建了一个带有下划线数据的表格,但我的要求如下图所示:

enter image description here

在此处输入图片说明

http://postimg.org/image/402ap3acf/

http://postimg.org/image/402ap3acf/

How can I build this type of table.

我怎样才能建立这种类型的表。

I need the below structure.

我需要以下结构。

    A/C Some text           TAT  Some text 
        -----------------        -----------------  

The doted lines are underline.

虚线是下划线。

回答by Chris Haas

The underline is controlled via the Fontobject and if you only want to set part of a Paragraphto be underlined you'll want to use a Chunk.

下划线是通过Font对象控制的,如果您只想将 a 的一部分设置Paragraph为下划线,您将需要使用Chunk.

Here's a quick helper method for generating a font with different styles. You can change the actual font to whatever font you want to use.

这是生成具有不同样式的字体的快速助手方法。您可以将实际字体更改为您想要使用的任何字体。

Private Shared Function CreateFont(size As Integer, Optional style As Integer = iTextSharp.text.Font.NORMAL) As iTextSharp.text.Font
    Return New iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, size, style)
End Function

The styleparameter takes integers from this list that you ORtogether:

style参数从这个列表中获取整数,你OR一起:

iTextSharp.text.Font.NORMAL
iTextSharp.text.Font.BOLD
iTextSharp.text.Font.ITALIC
iTextSharp.text.Font.UNDERLINE
iTextSharp.text.Font.STRIKETHRU

So normal underlined text would be:

所以正常的带下划线的文本是:

iTextSharp.text.Font.NORMAL Or iTextSharp.text.Font.UNDERLINE

You can use the above like this:

您可以像这样使用上述内容:

Dim P As New Paragraph()
P.Add(New Chunk("A/C ", CreateFont(12, iTextSharp.text.Font.NORMAL)))
P.Add(New Chunk("Some text", CreateFont(12, iTextSharp.text.Font.NORMAL Or iTextSharp.text.Font.UNDERLINE)))

EDIT

编辑

From iTextSharp's perspective, "underline" means "a line drawn underneath text". If there's no text there won't be an underline. A space, however, counts as text so you can just add extra spaces if you want like to continue the underline:

从 iTextSharp 的角度来看,“下划线”的意思是“在文本下方绘制的一条线”。如果没有文字,就不会有下划线。但是,空格算作文本,因此如果您想继续下划线,您可以添加额外的空格:

Dim P As New Paragraph()
P.Add(New Chunk("A/C ", CreateFont(12, iTextSharp.text.Font.NORMAL)))
P.Add(New Chunk("Some text    ", CreateFont(12, iTextSharp.text.Font.NORMAL Or iTextSharp.text.Font.UNDERLINE)))