如何使用chunk.setUnderline实现虚线下划线? [英] How to achieve a dashed underline using chunk.setUnderline?
问题描述
我使用 SAXItexthandler
来实现指定厚度,颜色和放大的自定义下划线。使用以下代码指定Y位置。所以基本上我在一个itext行的多个itext单元格中有不同的字符串,下面的代码帮助我为每个chunk做一个下划线,其中每个块都嵌入在一个单元格中,并且它工作得非常好。
I use SAXItexthandler
to achieve custom underlining of specified thickness, color & specified Y position using the below code. So basically i have different strings in multiple itext cells in a itext row and the below code helps me to do the underlining for every chunk where every chunk is embedded within a cell and it works perfectly fine.
Color c = Color.decode(custom_color);
currentChunk.setUnderline(c, thickness, 0.01f, ypos, 0.01f, PdfContentByte.LINE_CAP_BUTT);
现在我有办法让下划线虚线吗?我大量使用上面的代码,我们只在几个地方对虚线下划线有了新的要求。所以我想知道我是否可以使用 setUnderline
本身来实现它。
Now is there a way i can just make the underline dashed? I use the above code heavily and we have a new requirement for dashed underlines only in a few places. So i would like to know if i can achieve it using setUnderline
itself.
推荐答案
您可以在块上使用通用标记:
You can use generic tags on chunks:
- 在相关块上设置标记
- 创建一个扩展
PdfPageEventHelper
的类并将其添加到编写器 - 在<$ c $上编写使下划线作业的代码c> onGenericTag 方法
- 在
onGenericTag
方法中,您可以获得块的周围矩形:您可以使用虚线样式或任何你想要的样式直接在PdfContentByte上画一条线。
- Set the tag on relevant chunks
- Create a class that extends
PdfPageEventHelper
and add it to the writer - Write the code that makes the underlining job on the
onGenericTag
method - In the
onGenericTag
method you have the surrounding rect of the chunk: you can draw a line directly on the PdfContentByte using a dashed style or whatever style you desire.
这篇关于如何使用chunk.setUnderline实现虚线下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!