在*当前位置*绘制一个矩形,然后获取其位置坐标 [英] Draw a rectangle at the *current position* and then get its position coordinates

查看:465
本文介绍了在*当前位置*绘制一个矩形,然后获取其位置坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我写一些文本使用iTextSharp的PDF文件

So, I am writing some text into a PDF file using iTextSharp.

已经增加了几个段落和短语的PDF文档后,我想:

After having added a few paragraphs and phrases to the PDF document, I want to:

画上,有一个填充颜色,比如红色长方形顶部的下一段文字。

Draw the next piece of text on top of a rectangle that has a fill color, say, red.

我可以计算所需的宽度和高度,矩形必须根据我将在它上面写的文字的文本度量。但我怎么告诉长方形 API什么是顶部和左侧坐标,如其中的必须得出?

I can compute the required width and height that the rectangle must have based on the text metrics of the text I am going to write on top of it. But how do I tell the Rectangle API what is top and left coordinates are, as in where it must be drawn?

推荐答案

看来你正在寻找的 Chunk.setBackground() 方法。这吸引了一些文字下方的彩色背景。还有,如果你需要一个更大或更小的矩形需要额外的参数方法的变化。

Seems that you are looking for the Chunk.setBackground() method. This draws a colored background underneath some text. There's also a variation of the method that takes extra parameters if you need a larger or smaller rectangle.

假设你不想要一个彩色矩形,而是一个自定义类型形状,然后你会使用页面事件的 onGenericTag()。请参见块>了解更多信息通用标记

Suppose that you don't want a colored rectangle, but a custom type of shape, then you'd use the page event onGenericTag(). See Chunk > Generic tag for more info.

onGenericTag()方法被触发每次标记为通用(使用 setGenericTag() 法)呈现一个页面。然后,您执行的页面事件可以使用传递到事件方法矩形值。要明白,单个标记为通用代码可导致该方法的多个调用是很重要的:如果一个块中的内容需要分布在不同的线路,因为有行(给你的每一个单独的行一个单独的长方形值时将触发多次)。

The onGenericTag() method is triggered every time a Chunk that is marked as generic (using the setGenericTag() method) is rendered to a page. Your implementation of the page event can then use the Rectangle value that is passed to the event method. It is important to understand that a single Chunk marked as a generic tag can result in multiple invocations of this method: if the contents of a single Chunk needs to be distributed over different lines, the event will be triggered as many times as there are lines (giving you a separate Rectangle value for every separate line).

这篇关于在*当前位置*绘制一个矩形,然后获取其位置坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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