Drawing diagonal line in a cell of a table in iTExt?

匿名 (未验证) 提交于 2019-12-03 10:24:21

问题:

I'm creating a table in iText, but I've a problem with a cell that could be divided by a diagonal line. Someone know how can I do that?

回答1:

The easiest way would be via an onGenericTag handler in a PdfPageEvent.

You give the contents of that cell a generic tag via Chunk.setGenericTag(String tag), and set up a PdfPageEvent hanlder that will draw your line when that chunk is drawn.

Something like:

public class MyPdfPageEvent extends PdfPageEventHelper {   public void onGenericTag(PdfWriter writer, Document doc, Rectangle rect, String tag) {       PdfContentByte canvas = writer.getDirectContent();       canvas.saveState();       canvas.setColorStroke(Color.BLACK); // or whatever       // You can also mess with the line's thickness, endcaps, dash style, etc.       // Lots of options to play with.       canvas.moveTo(rect.getLeft(), rect.getBottom());       canvas.lineTo(rect.getRight(), rect.getTop());       canvas.stroke();       canvas.restoreState();   } } 


回答2:

Well. The answer of @Mark Storer was helpful, in this case there was a cell of a table I used "PdfPCellEvent" to inherid this methods.

Thanks Mark!



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