itextsharp测量块宽度/高度 [英] itextsharp measure chunk width / height

查看:113
本文介绍了itextsharp测量块宽度/高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试与iTextSharp进行一些精确的对齐,但是我一直在努力,因为我无法找到获得块或段落的宽度/高度值的方法。如果我创建一个特定字体和大小的字段和文本,那么它的尺寸应该是已知的,对吗?

I am trying to do some precise alignment with iTextSharp, but I keep falling short as I can't figure out a way to get a width / height value for a chunk or paragraph. If I create a paragraph that is a certain font and size and text, then its dimensions should be known, right?

我知道默认的左/右/中心对齐我会主要为我做这个伎俩,但我知道尺寸最有用的场景。有什么想法吗?

I know that the default left/right/center alignments will do the trick for me mostly, but I have scenarios where knowing the dimensions will be most useful. Any ideas?

推荐答案

你可以使用 GetWidthPoint()并且块的高度通常是字体的大小,除非您只使用小写字母。如果是这样,那么您可以使用 BaseFont.GetCharBBox()手动测量字符。

You can get a chunk's width using GetWidthPoint() and the height of a chunk is generally the font's size unless you're using only lowercase letters. If so then you can manually measure characters using BaseFont.GetCharBBox().

段落是可流动的项目,但是,它们取决于它们写入的背景,因此测量它们更难。 (Chunks不会自动换行但Paragraph会这样做。)测量段落的最佳方法是将其写入 PdfCell 然后测量 PdfCell 。您不必将 PdfCell 实际添加到文档中。下面的链接解释了一下。

Paragraphs are flowable items, however, and they depend on the context that they are written into so measuring them is harder. (Chunks don't automatically wrap but Paragraphs do.) The best way to measure a paragraph is to write it to a PdfCell and then measure the PdfCell. You don't have to actually add the PdfCell to the document. The link below explains it a little more.

http://itext-general.2136553.n4.nabble.com/Linecount-td2146114.html

这篇关于itextsharp测量块宽度/高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆