在iTExt中的表格的单元格中绘制对角线? [英] Drawing diagonal line in a cell of a table in iTExt?

查看:826
本文介绍了在iTExt中的表格的单元格中绘制对角线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 iText 中创建一个表格,但我的细胞可能会被对角线划分出来。有人知道我该怎么办?

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?

推荐答案

最简单的方法是通过一个 onGenericTag 处理程序code> PdfPageEvent 。

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

您可以通过 Chunk.setGenericTag为该单元格的内容提供通用标记(字符串标记),并设置一个PdfPageEvent hanlder,它将在绘制该块时绘制您的线。

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.

类似于:

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

这篇关于在iTExt中的表格的单元格中绘制对角线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆