问题
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:
- Set the tag on relevant chunks
- Create a class that extends
PdfPageEventHelperand add it to the writer - Write the code that makes the underlining job on the
onGenericTagmethod - In the
onGenericTagmethod 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