How to achieve a dashed underline using chunk.setUnderline?

女生的网名这么多〃 提交于 2019-12-24 20:34:15

问题


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);

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.


回答1:


You can use generic tags on chunks:

  1. Set the tag on relevant chunks
  2. Create a class that extends PdfPageEventHelper and add it to the writer
  3. Write the code that makes the underlining job on the onGenericTag method
  4. 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.


来源:https://stackoverflow.com/questions/11672384/how-to-achieve-a-dashed-underline-using-chunk-setunderline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!