Gopal SA
Gopal SA

Reputation: 959

How to achieve a dashed underline using chunk.setUnderline?

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.

Upvotes: 0

Views: 927

Answers (1)

Pier Luigi
Pier Luigi

Reputation: 7871

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.

Upvotes: 1

Related Questions