iTextSharp 在页面上随机位置的文本(标题)下绘制线条

发布于 2024-11-15 12:11:52 字数 767 浏览 1 评论 0 原文

有谁知道如何在可能位于页面上随机位置的标题(粗体文本的短行)下画一条线。

例如,

My Heading 1
---------------------------------------------- 

Some random paragraph


My Heading 2
----------------------------------------------

我可以像上面那样使用一行下划线 _ 来完成此操作,但是为了使该行靠近标题,我必须将字体大小设置为 2,这会导致一条参差不齐的丑陋线条。

我还可以在彼此的顶部添加两个块(一个带有标题,一个带有 _),类似于本文中的第一个示例 http://www.mikesdotnetting.com/Article/82/iTextSharp-Adding-Text-with-Chunks-Phrases-and-Paragraphs 使用相同的字体大小,但似乎这只是在页面顶部工作,一旦我添加其他段落并尝试在页面中间进行操作,两个块就会分开,并在第一个块的末尾有一个清晰的换行符。

似乎你可以在 iTextSharp 中画线,但我不知道如何计算坐标,因为我见过的所有示例都使用此方法在页面顶部或底部的固定位置放置一条线。

非常感谢任何帮助。

干杯 抢

does anyone know how I can draw a line under a heading (a short line of bold text) that may be located in a random location on a page.

e.g.

My Heading 1
---------------------------------------------- 

Some random paragraph


My Heading 2
----------------------------------------------

I can do it as I have done above using a line of Underscores _ but in order to get the line anywhere near the heading I have to set the font size at 2 which results in a spotty ugly line.

I can also add two chunks over the top of each other (one with the heading and one with _) similar to the first example in this article http://www.mikesdotnetting.com/Article/82/iTextSharp-Adding-Text-with-Chunks-Phrases-and-Paragraphs using the same font size but it seems that this only works at the top of the page, once I add other paragraphs and try to do it mid-way down the page the two chunks separate with a clear line-break at the end of the first chunk.

It seems you can draw lines in iTextSharp but I have no idea how to calculate the coordinates, as all the examples I have seen use this method to place a line at the top or bottom of the page in a fixed location.

Any help greatly appreciated.

Cheers
Rob

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吖咩 2024-11-22 12:11:52

LineSeperator 对象可能就是您正在寻找的对象。用一块包裹它并将其放在您需要的地方。

这是行分隔符示例:

Chunk linebreak = new Chunk(new LineSeparator(4f, 100f, colorGrey, Element.ALIGN_CENTER, -1));
doc.Add(linebreak);

The LineSeperator object might be what you're looking for. Wrap it with a chunk and put it where you need it.

Here's a sample line seperator:

Chunk linebreak = new Chunk(new LineSeparator(4f, 100f, colorGrey, Element.ALIGN_CENTER, -1));
doc.Add(linebreak);
北凤男飞 2024-11-22 12:11:52

我知道这是一篇较旧的帖子,但是也许这会对某人有所帮助。

//Create Chunk for underline
Chunk chkHeader = new Chunk("My Title", fnt13Bold);
chkHeader.SetUnderline(1f, -2f);
//Add Chunk to paragraph
Paragraph pHeader = new Paragraph(chkHeader);

I know this is an older post but, maybe this will help somebody.

//Create Chunk for underline
Chunk chkHeader = new Chunk("My Title", fnt13Bold);
chkHeader.SetUnderline(1f, -2f);
//Add Chunk to paragraph
Paragraph pHeader = new Paragraph(chkHeader);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文